public void selectEntry ( byte [ ] remoteZID ) { platform . getLogger ( ) . log ( "ZRTPCache: selectEntry(" + platform . getUtils ( ) . byteToHexString ( remoteZID ) + ")" ) ; String zidString = new String ( remoteZID ) ; if ( currentZid != null && currentZid . equals ( zidString ) ) { return ; } currentZid = null ; currentRs1 = null ; currentRs2 = null ; currentTrust = false ; currentNumber = null ; ZrtpCacheEntry ce = cache . get ( zidString ) ; if ( ce == null ) { currentZid = zidString ; return ; } byte [ ] data = ce . getData ( ) ; if ( data . length == 40 || data . length == 72 ) { // backward compatibility: insert trust flag = false byte [ ] newData = new byte [ 1 + data . length ] ; newData [ 0 ] = 0 ; System . arraycopy ( data , 0 , newData , 1 , data . length ) ; data = newData ; } if ( data . length != 41 && data . length != 73 ) { platform . getLogger ( ) . logWarning ( "Invalid shared secret cache entry" ) ; currentZid = zidString ; return ; } long expiry = 0 ; for ( int i = 8 ; i != 0 ; ) { expiry = ( expiry << 8 ) + ( data [ -- i ] & 0xff L ) ; } long now = System . currentTimeMillis ( ) ; if ( expiry > now ) { currentTrust = ( data [ 8 ] != 0 ) ; currentRs1 = new byte [ 32 ] ; System . arraycopy ( data , 9 , currentRs1 , 0 , 32 ) ; if ( data . length == 73 ) { currentRs2 = new byte [ 32 ] ; System . arraycopy ( data , 41 , currentRs2 , 0 , 32 ) ; } } currentNumber = ce . getNumber ( ) ; currentZid = zidString ; // //// TEST if ( UPDATE_FOR_CACHE_MISMATCH_SIMULATION ) { if ( currentRs1 != null ) currentRs1 = platform . getCrypto ( ) . getRandomGenerator ( ) . getBytes ( currentRs1 . length ) ; if ( currentRs2 != null ) currentRs2 = platform . getCrypto ( ) . getRandomGenerator ( ) . getBytes ( currentRs2 . length ) ; if ( currentRs1 != null || currentRs2 != null ) { updateEntry ( expiry , currentTrust , currentRs1 , currentRs2 , currentNumber ) ; } UPDATE_FOR_CACHE_MISMATCH_SIMULATION = false ; } // //// TEST currentTrust &= ( platform . getAddressBook ( ) . isInAddressBook ( currentNumber ) ) ; }
Selects a cache entry base on remote ZID