|  |  | 
 |  |  |  | 
 |  |  | import java.security.MessageDigest; | 
 |  |  | import java.security.NoSuchAlgorithmException; | 
 |  |  | import java.text.DecimalFormat; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.time.Instant; | 
 |  |  | import java.util.Random; | 
 |  |  |  | 
 |  |  | import javax.sip.address.URI; | 
 |  |  | 
 |  |  |      * @return a generated nonce. | 
 |  |  |      */ | 
 |  |  |     private String generateNonce() { | 
 |  |  |         // Get the time of day and run MD5 over it. | 
 |  |  |         Date date = new Date(); | 
 |  |  |         long time = date.getTime(); | 
 |  |  |         long time = Instant.now().toEpochMilli(); | 
 |  |  |         Random rand = new Random(); | 
 |  |  |         long pad = rand.nextLong(); | 
 |  |  |         // String nonceString = (new Long(time)).toString() | 
 |  |  |         //         + (new Long(pad)).toString(); | 
 |  |  |         String nonceString = Long.valueOf(time).toString() | 
 |  |  |                 + Long.valueOf(pad).toString(); | 
 |  |  |         byte mdbytes[] = messageDigest.digest(nonceString.getBytes()); | 
 |  |  |         // Convert the mdbytes array into a hex string. | 
 |  |  |         return toHexString(mdbytes); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |      */ | 
 |  |  |     public boolean doAuthenticateHashedPassword(Request request, String hashedPassword) { | 
 |  |  |         AuthorizationHeader authHeader = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME); | 
 |  |  |         if ( authHeader == null ) return false; | 
 |  |  |         if ( authHeader == null ) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |         String realm = authHeader.getRealm(); | 
 |  |  |         String username = authHeader.getUsername(); | 
 |  |  |  | 
 |  |  | 
 |  |  |      */ | 
 |  |  |     public boolean doAuthenticatePlainTextPassword(Request request, String pass) { | 
 |  |  |         AuthorizationHeader authHeader = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME); | 
 |  |  |         if ( authHeader == null ) return false; | 
 |  |  |         if ( authHeader == null ) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |         String realm = authHeader.getRealm().trim(); | 
 |  |  |         String username = authHeader.getUsername().trim(); | 
 |  |  |  | 
 |  |  | 
 |  |  |         logger.debug("qop: " + qop); | 
 |  |  |         String KD = HA1 + ":" + nonce; | 
 |  |  |  | 
 |  |  |         if (qop != null && qop.equals("auth") ) { | 
 |  |  |         if (qop != null && qop.equalsIgnoreCase("auth") ) { | 
 |  |  |             if (nc != -1) { | 
 |  |  |                 KD += ":" + ncStr; | 
 |  |  |             } |