SSL Session Keys

Hi,
As I understand it, in the process of making an SSL connection (during the handshake) certificates are exchanged and their identities are authenticated, and then each create an identical (symetric) session key which will be used to encrypt communication.
My questions are:
1) What algorithm/encryption engine is used to create this key?
2) How strong is the algorithm that generates the key, and what type of key is used?
3) How can custom cyrptographic providers be used with SSL to generate these session keys?
4) Is there a way to force the SSL connection to use one specific method of generating the session key, and fail if it can't?
5) Is there a web page that gives me the deatail on these topics?
I've been looking around, but I can't find the answers to these specific questions.
Any help would be much appreciated, thanks,
Jason

You may consider to look on the following resources:
SSL v3 http://ssllib.sourceforge.net/draft302.txt
SSL v2 http://ssllib.sourceforge.net/SSLv2.spec.html
TLS v1 http://ssllib.sourceforge.net/rfc2246.txt
SSL and TLS book http://www.rtfm.com/sslbook/
JSSE Guide
http://java.sun.com/j2se/1.4/docs/guide/security/jsse/JSSERefGuide.html
http://java.sun.com/j2se/1.4/docs/guide/security/jsse/JSSERefGuide.html#SSLDocs
The algorithms used in SSL hanshake and then in data transmition are driven by the choosen cipher suite http://java.sun.com/j2se/1.4/docs/guide/security/jsse/JSSERefGuide.html#CipherSuite I.e. TLS_RSA_WITH_RC4_128_MD5. See SSLSocket documentation on how to set enabled suites - http://java.sun.com/j2se/1.4/docs/api/javax/net/ssl/SSLSocket.html#setEnabledCipherSuites(java.lang.String[])

Similar Messages

  • Get ssl session key after handshaking

    hi..i want to get ssl session key (after ssl handshaking) to insert in cookie (hashed using HMAC) to avoid reply attack. but i don't know how to get that from container (i used tomcat). what must i do?

    i mean reply attack for cookieDo you mean replay+ attack for cookie?
    I have read the paperWhat paper? Reference? URL?
    are you sure there is no way to get session key from container into servlet?I've answered that, but it isn't the container that has the session key. It is the SSLSession actually.

  • Proxyless clustering and SSL session state

    The current 6.0 docs are a bit quiet on SSL and clustering, so can I check
              whether it is the case that when proxy-less clustering is used with SSL, a
              failover results in a new certificate exchange and crypto session
              establishment? In other words, the clustering isn't attempting to replicate
              the SSL session state or similar super-subtle strategy.
              Thanks!
              Alex Thomas
              Lehman Brothers
              London
              

              "Alex Thomas" <[email protected]> wrote in message
              news:[email protected]..
              > The current 6.0 docs are a bit quiet on SSL and clustering, so can I check
              > whether it is the case that when proxy-less clustering is used with SSL, a
              > failover results in a new certificate exchange and crypto session
              > establishment? In other words, the clustering isn't attempting to
              replicate
              > the SSL session state or similar super-subtle strategy.
              Alex,
              A failover will result in a new SSL connection being started. As you say
              this will mean that certificate exchange and session key exchange will occur
              again. All of the replicated state is kept at a higher level in the server
              so that we can use different SSL implementations including hardware
              accelerators.
              Regards,
              Adam
              

  • SSL session cache memory consumption

    Hello,
    I am implementing a high availability application that uses SSL session caching. How much memory does it consume? I mean, is setting session cache size to unlimited a 'safe' option?
    Thanks.

    Not for a server, limit it to something. It's in the server's interest to keep sessions few and short-lived, but conversely it's in the client's interest to keep sessions many and long-lived.
    A 'session' object contains the master secret and the current session key, and references to the peer certificate chain.

  • Session key and MAC generation in SCP '02' i='15'

    Hi,
    I am trying send a PUT KEY command and it resolves to '6982' after a '9000' EXTERNAL AUTHENTICATE.
    I suspect that my encryption is causing the problem.(not really sure!)
    I compare my session keys to some that ppl had derived and posted on the forum and I don't really get what they did.
    I am trying to find out if I'm deriving the correct session keys or not?!?!
    e.g
    //Calculating session keys with
    //static key = '404142434445464748494a4b4c4d4e4f' (keyData)
    //sequence counter = '003b'
    //"0101" + sequenceCounter + "000000000000000000000000" for session CMAC key (data)
    //"0102" + sequenceCounter + "000000000000000000000000" for session RMAC key (data)
    //"0181" + sequenceCounter + "000000000000000000000000" for session DEK key (data)
    //"0182" + sequenceCounter + "000000000000000000000000" for session ENC key (data)
    //sessionCMAC is :3213860da8f8d9796794cbcec43ef7a23213860da8f8d979: with sequence counter:003b (result)
    //sessionRMAC is :042a687f6e0dd3f80eabf1e5d51ccefe042a687f6e0dd3f8: with sequence counter:003b (result)
    //sessionDEK is :1fe31370c22354e3b90d6b8ad5686d371fe31370c22354e3: with sequence counter:003b (result)
    //sessionENC is :94a47ad54ffbf423fe4a9d915befab5294a47ad54ffbf423: with sequence counter:003b (result)
    <code>
    if (keyData.length == 16) {
    byte[] temp = (byte[]) keyData.clone();
    keyData = new byte[24];
    System.arraycopy(temp, 0, keyData, 0, temp.length);
    System.arraycopy(temp, 0, keyData, 16, 8);
    DESedeKeySpec keySpec = new DESedeKeySpec(keyData);
    SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DESede");
    SecretKey key = secretKeyFactory.generateSecret(keySpec);
    IvParameterSpec iv = new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
    Cipher desedeCBCCipher = Cipher.getInstance("DESede/CBC/NoPadding");
    desedeCBCCipher.init(Cipher.ENCRYPT_MODE, key, iv);
    byte[] result = desedeCBCCipher.doFinal(data);
    if (result .length == 16) {
    byte[] temp = (byte[]) result .clone();
    result = new byte[24];
    System.arraycopy(temp, 0, result , 0, temp.length);
    System.arraycopy(temp, 0, result , 16, 8);
    keySpec = new DESedeKeySpec(result);
    secretKeyFactory = SecretKeyFactory.getInstance("DESede");
    key = secretKeyFactory.generateSecret(keySpec);
    </code>
    I use the same encrytion to derive KeyCheckValue with
    newKey ='505152535455565758595a5b5c5d5e5f', data = '0000000000000000'
    and it results to : '6d377e' (of course the last 3 bytes)
    Even though my CMAC session key is different from others (e.g "RLopes" in "http://192.9.162.102/thread.jspa?threadID=5365173&tstart=363" and I have seen it in others too and its really odd to me that its slightly different if you take a close look you will get what i mean) i get the EXTERNAL AUTHENTICATION to work.
    If there is anyone who is 100% sure meaning he/she got other commands to work after EXTERNAL AUTHENTICATE using CMAC please help me verify the keys I got?
    Can he/she test with his code to see if he/she is getting the same session keys or check value?
    Thanks in advance
    Kamran

    Hi,
    Here is the Class and thanks for the tip, I've honestly tried these <code></code> but didn't work and I know it is indeed annoying without the tags :D
    I really hope it helps...
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package terminalpcsc;
    import java.lang.Exception;
    import java.security.GeneralSecurityException;
    import java.security.Key;
    import java.security.SecureRandom;
    import java.util.List;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import javax.security.sasl.AuthenticationException;
    import javax.smartcardio.*;
    * @author Kamran
    * @param args the command line arguments
    public class Main {
        private static CardChannel channel;
        private static Card card;
        private static int CHALLENGE_LENGTH = 8;
        private static byte[] keyDiversification = new byte[10];
        private static byte[] keyInformation = new byte[2];
        private static byte[] sequenceCounter = new byte[2];
        private static byte[] cardChallenge = new byte[6];
        private static byte[] cardCryptogram = new byte[8];
        private static byte[] hostChallenge = new byte[8];
        private static byte[] hostCryptogram = new byte[8];
        private static String keyDiversificationHexString;
        private static String keyInformationHexString;
        private static String sequenceCounterHexString;
        private static String cardChallengeHexString;
        private static String cardCryptogramHexString;
        private static String hostChallengeHexString;
        private static String hostCryptogramHexString;
        private static byte[] sessionCMAC;
        private static byte[] sessionDEK;
        private static byte[] sessionENC;
        private static byte[] sessionRMAC;
        private static byte[] icvNextCommand;
        private static IvParameterSpec ivAllZeros = new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
        private static byte[] staticKey = hexStringToByteArray("404142434445464748494a4b4c4d4e4f4041424344454647");
        private static byte[] newKey = hexStringToByteArray("505152535455565758595a5b5c5d5e5f");
        private static byte[] CMAC;
         * @param args the command line arguments
        public static void main(String[] args) throws Exception {
            initiateCardChannel();
            String apduString = generateSelectAPDU("a000000003535041");
            byte[] bufferC = hexStringToByteArray(apduString);
            CommandAPDU capdu = new CommandAPDU(bufferC);
            System.out.println("Sending APDU Select AID: " + byteArrayToHexString(bufferC));
            ResponseAPDU rapdu = channel.transmit(capdu);
            System.out.println("Sending Apdu: Done!");
            System.out.println("Waiting For Response...");
            byte[] bufferR = rapdu.getData();
            String responseData = byteArrayToHexString(rapdu.getBytes());
            System.out.println("Response: " + responseData);
            apduString = generateInitializeUpdateAPDU();
            bufferC = hexStringToByteArray(apduString);
            capdu = new CommandAPDU(bufferC);
            System.out.println("Sending APDU Initialize Update: " + byteArrayToHexString(bufferC));
            rapdu = channel.transmit(capdu);
            System.out.println("Sending Apdu: Done!");
            System.out.println("Waiting For Response...");
            bufferR = rapdu.getData();
            responseData = byteArrayToHexString(rapdu.getBytes());
            System.out.println("Response: " + responseData);
            // protocol 01
            //System.arraycopy(bufferR,0,keyDiversification,0,10);
            //System.arraycopy(bufferR,10,keyInformation,0,2);
            //System.arraycopy(bufferR,12,cardChallenge,0,8);
            //System.arraycopy(bufferR,20,cardCryptogram,0,8);
            // protocol 02
            System.arraycopy(bufferR, 0, keyDiversification, 0, 10);
            System.arraycopy(bufferR, 10, keyInformation, 0, 2);
            System.arraycopy(bufferR, 12, sequenceCounter, 0, 2);
            System.arraycopy(bufferR, 14, cardChallenge, 0, 6);
            System.arraycopy(bufferR, 20, cardCryptogram, 0, 8);
            keyDiversificationHexString = byteArrayToHexString(keyDiversification);
            keyInformationHexString = byteArrayToHexString(keyInformation);
            sequenceCounterHexString = byteArrayToHexString(sequenceCounter);
            cardChallengeHexString = byteArrayToHexString(cardChallenge);
            cardCryptogramHexString = byteArrayToHexString(cardCryptogram);
            System.out.println("keyDiversification: " + keyDiversificationHexString);
            System.out.println("keyInformation: " + keyInformationHexString);
            System.out.println("sequenceCounter: " + sequenceCounterHexString);
            System.out.println("cardChallenge: " + cardChallengeHexString);
            System.out.println("cardCryptogram: " + cardCryptogramHexString);
            System.out.println("Calculating Session Keys... encryption with CBC");
            //E.4.1 GP 2.1.1
            sessionCMAC = deriveEncryptionCBC(staticKey, hexStringToByteArray("0101" + sequenceCounterHexString + "000000000000000000000000"));
            System.out.println("sessionCMAC is :" + byteArrayToHexString(sessionCMAC) + ": with sequence counter:" + sequenceCounterHexString);
            sessionRMAC = deriveEncryptionCBC(staticKey, hexStringToByteArray("0102" + sequenceCounterHexString + "000000000000000000000000"));
            System.out.println("sessionRMAC is :" + byteArrayToHexString(sessionRMAC) + ": with sequence counter:" + sequenceCounterHexString);
            sessionDEK = deriveEncryptionCBC(staticKey, hexStringToByteArray("0181" + sequenceCounterHexString + "000000000000000000000000"));
            System.out.println("sessionDEK is :" + byteArrayToHexString(sessionDEK) + ": with sequence counter:" + sequenceCounterHexString);
            sessionENC = deriveEncryptionCBC(staticKey, hexStringToByteArray("0182" + sequenceCounterHexString + "000000000000000000000000"));
            System.out.println("sessionENC is :" + byteArrayToHexString(sessionENC) + ": with sequence counter:" + sequenceCounterHexString);
            System.out.println("Calculating and Verifying Card Cryptogram...");
            byte[] signature = cbcMACSignature(hexStringToByteArray(hostChallengeHexString + sequenceCounterHexString + cardChallengeHexString + "8000000000000000"), sessionENC);
            String signatureHexString = byteArrayToHexString(signature);
            if (signatureHexString.equalsIgnoreCase(cardCryptogramHexString)) {
                System.out.println("signature is :" + signatureHexString + "\ncardCryptogram is :" + cardCryptogramHexString + " \nCard cryptogram authenticated");
                apduString = generateExternalAuthenticateAPDU();
                bufferC = hexStringToByteArray(apduString);
                capdu = new CommandAPDU(bufferC);
                System.out.println("Sending APDU External Authenticate: " + byteArrayToHexString(bufferC));
                rapdu = channel.transmit(capdu);
                System.out.println("Sending Apdu: Done!");
                System.out.println("Waiting For Response...");
                bufferR = rapdu.getData();
                responseData = byteArrayToHexString(rapdu.getBytes());
                System.out.println("Response: " + responseData);
                apduString = generatePutKeyAPDU();
                bufferC = hexStringToByteArray(apduString);
                capdu = new CommandAPDU(bufferC);
                System.out.println("Sending APDU Put Key: " + byteArrayToHexString(bufferC));
                rapdu = channel.transmit(capdu);
                System.out.println("Sending Apdu: Done!");
                System.out.println("Waiting For Response...");
                bufferR = rapdu.getData();
                responseData = byteArrayToHexString(rapdu.getBytes());
                System.out.println("Response: " + responseData);
            } else {
                System.out.println("signature is :" + signatureHexString + "\ncardCryptogram is :" + cardCryptogramHexString + " \nCard cryptogram is not authenticated");
            releaseCardChannel();
        public static byte[] cbcMACSignature(byte[] data, byte[] sessionSENC) throws AuthenticationException {
            IvParameterSpec params =
                    new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
            if (sessionSENC.length == 16) {
                byte[] temp = (byte[]) sessionSENC.clone();
                sessionSENC = new byte[24];
                System.arraycopy(temp, 0, sessionSENC, 0, temp.length);
                System.arraycopy(temp, 0, sessionSENC, 16, 8);
            byte[] temp = null;
            SecretKey secretKey = new SecretKeySpec(sessionSENC, "DESede");
            try {
                Cipher cbcDES = Cipher.getInstance("DESede/CBC/NoPadding");
                cbcDES.init(Cipher.ENCRYPT_MODE, secretKey, params);
                temp = cbcDES.doFinal(data);
            } catch (GeneralSecurityException e) {
                e.printStackTrace();
            byte[] signature = new byte[8];
            System.arraycopy(temp, temp.length - 8, signature, 0, signature.length);
            return signature;
        // generateInitialUpdateAPDU()
        //CLA '80'
        //INS '50' INITIALIZE UPDATE
        //P1 'xx' Key Version Number
        //P2 '00' Reference control parameter P2
        //Lc '08' Length of host challenge
        //Data 'xx xx…' Host challenge
        //Le '00'
        //RESPONSE TEMPLATE
        //Key diversification data 10 bytes
        //Key information 2 bytes
        //Card challenge 8 bytes
        //Card cryptogram 8 bytes
        public static String generateInitializeUpdateAPDU() throws Exception {
            hostChallenge = generateHostChallenge();
            hostChallengeHexString = byteArrayToHexString(hostChallenge);
            return "8050000008" + hostChallengeHexString + "00";
        //CLA '80' or '84'
        //INS 'D8' PUT KEY
        //P1 'xx' Reference control parameter P1 Key Version Number -- '00' is new key  range is '01' to '7F'
        //P2 'xx' Reference control parameter P2 Key Identifier     -- '00' to '7F'
        //Lc 'xx' Length of data field
        //Data 'xxxx..' Key data (and MAC if present)
        //Le '00'
        public static String generatePutKeyAPDU() throws Exception {
            String keyCheckValue = new String();
            //keyCheckValue = keyCheckValue.substring(keyCheckValue.length() - (3 * 2));
            keyCheckValue = byteArrayToHexString(deriveEncryptionECB(newKey, hexStringToByteArray("0000000000000000")));
            keyCheckValue = keyCheckValue.substring(keyCheckValue.length() - (3 * 2));
            System.out.println("keyCheckValue :" + keyCheckValue + " 3DES ECB, key is new key '505152535455565758595a5b5c5d5e5f5051525354555657', data is 8 zeroes");
            String encryptedNewKey = byteArrayToHexString(deriveEncryptionECB(sessionDEK, newKey));
            //System.out.println("sessionDEK.getEncoded() :" + sessionDEK.getEncoded() + " len is:" + sessionDEK.getEncoded().length);
            System.out.println("encryptedNewKey :" + encryptedNewKey);
            //testing newKey
            String dataField = "01" + "8010" + encryptedNewKey + "03" + keyCheckValue + "8010" + encryptedNewKey + "03" + keyCheckValue + "8010" + encryptedNewKey + "03" + keyCheckValue;
            // String dataField2 = "01" + "8010" + byteArrayToHexString(newKey) + "03" + keyCheckValue + "8010" + byteArrayToHexString(newKey) + "03" + keyCheckValue + "8010" + byteArrayToHexString(newKey) + "03" + keyCheckValue;
            System.out.println("datafield to calculate cmac :" + dataField);
            System.out.println("icv to calculate cmac is previous mac first 8 byte sessionCMAC in CBC single des :" + byteArrayToHexString(icvNextCommand));
            CMAC = generateCMac2((byte) 0x84, (byte) 0xD8, (byte) 0x00, (byte) 0x81, hexStringToByteArray(dataField), sessionCMAC, icvNextCommand);
            System.out.println("data field with des padding for encryption (encryption in CBC sessionENC) :" + desPadding(dataField));
            String dataField3 = byteArrayToHexString(deriveEncryptionCBC(sessionENC, hexStringToByteArray(desPadding(dataField))));
            System.out.println("data field after encryption :" + dataField3);
            Integer CMACLen = byteArrayToHexString(CMAC).length() / 2;
            System.out.println("CMACLen :" + CMACLen);
            Integer dataFieldLen = dataField3.length() / 2;
            System.out.println("dataFieldLen :" + dataFieldLen);
            Integer intLc = dataFieldLen + CMACLen;
            System.out.println("intLc :" + intLc);
            String hexLc = Integer.toString(intLc, 16);
            System.out.println("hexLc :" + hexLc);
            return "84D80081" + hexLc + dataField3 + byteArrayToHexString(CMAC) + "00";
        //generateExternalAuthenticateAPDU()
        //CLA '84'
        //INS '82' EXTERNAL AUTHENTICATE
        //P1 'xx' Security level  --'03' C-DECRYPTION and C-MAC.--'01' C-MAC.'00' No secure messaging expected.
        //P2 '00' Reference control parameter P2
        //Lc '10' Length of host cryptogram and MAC
        //Data 'xx xx…' Host cryptogram and MAC
        //Le Not present
        public static String generateExternalAuthenticateAPDU() throws Exception {
            System.out.println("Calculating and Verifying Host Cryptogram...");
            hostCryptogram = cbcMACSignature(hexStringToByteArray(sequenceCounterHexString + cardChallengeHexString + hostChallengeHexString + "8000000000000000"), sessionENC);
            hostCryptogramHexString = byteArrayToHexString(hostCryptogram);
            System.out.println("hostCryptogram is :" + hostCryptogramHexString);
            CMAC = generateCMac2((byte) 0x84, (byte) 0x82, (byte) 0x03, (byte) 0x00, hostCryptogram, sessionCMAC, new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
            return "8482030010" + hostCryptogramHexString + byteArrayToHexString(CMAC);
        // generateSelectAPDU()
        //CLA '00' ISO/IEC 7816-4 command
        //INS 'A4' SELECT
        //P1 'xx' Reference control parameter P1 --'04' select by name
        //P2 'xx' Reference control parameter P2 --'00' First or only occurrence --'02' Next occurrence
        //Lc 'xx' Length of AID
        //Data 'xxxx..' AID of Application to be selected
        //Le '00'
        // RESPONSE TEMPLATE
        //'6F' File Control Information (FCI template) Mandatory
        //'84' Application / file AID Mandatory
        //'A5' Proprietary data Mandatory
        //'73' Security Domain Management Data (see Appendix F for detailed coding) Optional
        //'9F6E' Application production life cycle data Optional
        //'9F65' Maximum length of data field in command message Mandatory
        public static String generateSelectAPDU(String AID) throws Exception {
            String AIDlen = Integer.toString(AID.length() / 2, 16);
            if (AIDlen.length() == 1) {
                AIDlen = "0" + AIDlen;
            System.out.println("00A40400" + AIDlen + AID);
            return "00A40400" + AIDlen + AID;
        public static String byteArrayToHexString(byte[] b) throws Exception {
            String result = "";
            for (int i = 0; i < b.length; i++) {
                result +=
                        Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
            return result;
        public static void initiateCardChannel() throws CardException {
            System.out.println("Connecting to Java Card...");
            TerminalFactory factory = TerminalFactory.getDefault();
            List<CardTerminal> terminals = factory.terminals().list();
            System.out.println("Terminals Detected: " + terminals);
            // get the first terminal
            System.out.println("Connecting to: " + terminals + "...");
            CardTerminal terminal = terminals.get(0);
            System.out.println("Connected to: " + terminals);
            // establish a connection with the card
            System.out.println("Connecting to Java Card...");
            card = terminal.connect("T=0");
            System.out.println("Connected to card: " + card);
            System.out.println("Obtaining Channel...");
            channel = card.getBasicChannel();
            System.out.println("Connecting to Channel: " + channel.getChannelNumber());
        public static void releaseCardChannel() throws CardException {
            System.out.println("Disconnection all...");
            card.disconnect(false);
            System.out.println("Disconnection Done");
            System.out.println("*END*");
        public static byte[] hexStringToByteArray(String s) {
            int len = s.length();
            byte[] data = new byte[len / 2];
            for (int i = 0; i < len; i += 2) {
                data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
            return data;
        //To generate the derivation data:
        public static byte[] deriveEncryptionCBC(byte[] keyData, byte[] data) throws GeneralSecurityException {
            //Key key = getSecretKey(keyData);
            if (keyData.length == 16) {
                byte[] temp = (byte[]) keyData.clone();
                keyData = new byte[24];
                System.arraycopy(temp, 0, keyData, 0, temp.length);
                System.arraycopy(temp, 0, keyData, 16, 8);
            SecretKey secretKey = new SecretKeySpec(keyData, "DESede");
            IvParameterSpec dps =
                    new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
            String algorithm = "DESede/CBC/NoPadding";
            Cipher desedeCBCCipher = Cipher.getInstance(algorithm);
            desedeCBCCipher.init(Cipher.ENCRYPT_MODE, secretKey, dps);
            byte[] result = desedeCBCCipher.doFinal(data);
            //adjustParity(result);
            return result;
        public static byte[] deriveEncryptionECB(byte[] keyData, byte[] data) throws GeneralSecurityException {
            //Key key = getSecretKey(keyData);
            if (keyData.length == 16) {
                byte[] temp = (byte[]) keyData.clone();
                keyData = new byte[24];
                System.arraycopy(temp, 0, keyData, 0, temp.length);
                System.arraycopy(temp, 0, keyData, 16, 8);
            SecretKey secretKey = new SecretKeySpec(keyData, "DESede");
            String algorithm = "DESede/ECB/NoPadding";
            Cipher desedeCBCCipher = Cipher.getInstance(algorithm);
            desedeCBCCipher.init(Cipher.ENCRYPT_MODE, secretKey);
            byte[] result = desedeCBCCipher.doFinal(data);
            //adjustParity(result);
            return result;
         * Adjust a DES key to odd parity
         * @param key
         *            to be adjusted
        public static byte[] adjustParity(byte[] key) {
            for (int i = 0; i < key.length; i++) {
                int akku = (key[i] & 0xFF) | 1;
                for (int c = 7; c > 0; c--) {
                    akku = (akku & 1) ^ (akku >> 1);
                key[i] = (byte) ((key[i] & 0xFE) | akku);
            return key;
        public static byte[] generateCMac2(byte cla, byte ins, byte p1, byte p2, byte[] dataField, byte[] SMacSessionKey, byte[] icv) throws GeneralSecurityException, Exception {
            if (SMacSessionKey.length == 16) {
                byte[] temp = (byte[]) SMacSessionKey.clone();
                SMacSessionKey = new byte[24];
                System.arraycopy(temp, 0, SMacSessionKey, 0, temp.length);
                System.arraycopy(temp, 0, SMacSessionKey, 16, 8);
            byte[] cMac = new byte[8];
            byte[] padding = {(byte) 0x80, 0, 0, 0, 0, 0, 0, 0};
            int paddingRequired = 8 - (5 + dataField.length) % 8;
            byte[] data = new byte[5 + dataField.length + paddingRequired];
            //Build APDU
            data[0] = cla;
            data[1] = ins;
            data[2] = p1;
            data[3] = p2;
            data[4] = (byte) ((byte) dataField.length + (byte) 0x08);
            System.arraycopy(dataField, 0, data, 5, dataField.length);
            System.arraycopy(padding, 0, data, 5 + dataField.length, paddingRequired);
            System.out.println("data to calculate mac :" + byteArrayToHexString(data));
            System.out.println("icv to calculate mac :" + byteArrayToHexString(icv));
            Cipher cipher = Cipher.getInstance("DESede/CBC/NoPadding");
            Cipher singleDesCipher = Cipher.getInstance("DES/CBC/NoPadding", "SunJCE");
            SecretKeySpec desSingleKey = new SecretKeySpec(SMacSessionKey, 0, 8, "DES");
            SecretKey secretKey = new SecretKeySpec(SMacSessionKey, "DESede");
            //Calculate the first n - 1 block. For this case, n = 1
            IvParameterSpec ivSpec = new IvParameterSpec(icv);
            singleDesCipher.init(Cipher.ENCRYPT_MODE, desSingleKey, ivSpec);
            byte ivForLastBlock[] = singleDesCipher.doFinal(data, 0, 8);
            int blocks = data.length / 8;
            for (int i = 0; i < blocks - 1; i++) {
                singleDesCipher.init(Cipher.ENCRYPT_MODE, desSingleKey, ivSpec);
                byte[] block = singleDesCipher.doFinal(data, i * 8, 8);
                ivSpec = new IvParameterSpec(block);
            int offset = (blocks - 1) * 8;
            cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec);
            cMac = cipher.doFinal(data, offset, 8);
            ivSpec = new IvParameterSpec(new byte[8]);
            singleDesCipher.init(Cipher.ENCRYPT_MODE, desSingleKey, ivSpec);
            icvNextCommand = singleDesCipher.doFinal(cMac);
            return cMac;
        public static byte[] generateHostChallenge() {
            byte[] hostChallenge = new byte[CHALLENGE_LENGTH];
            SecureRandom random = new SecureRandom();
            random.nextBytes(hostChallenge);
            return hostChallenge;
        public static String desPadding(String hexString) {
            System.out.println("String to pad before:" + hexString);
            hexString = hexString + "80";
            int hexStringLen = hexString.length() / 2;
            int padding = 8 - (hexStringLen % 8);
            for (int i = 0; i < padding; i++) {
                hexString = hexString + "00";
            System.out.println("String to pad after :" + hexString);
            return hexString;
    }Thanks in advance
    Kamran

  • Facebook Export issue - session key validity?

    Love the new feature to upload to Facebook/Flickr - however, everything has been working fine until this morning, went to upload a jpg to Facebook and I get the following error message:
    "Bridge encountered and error while exporting: Session key invalid or no longer valid."
    The very same file just exported to Flickr no problems. Tried resetting the Module (re-creating from scratch), logged back into Facebook through Bridge, re-authorized, even restarted Bridge and made a completely new file to try in case that jpg was corrupt. Same error every time. I blame Facebook, just wondering if there's a workaround.
    Cheers on CS5!

    Sorry, should've mentioned, I did run the updater beforehand and am currently having these issues in 4.0.2.1
    EDIT 1:
    Solved (see below), per other post:
    In the export panel choose the tiny menu icon top right and click on manage modules. In this view there is also a toothed wheel icon. Click on it and choose reinstall all modules. After this you should restart Bridge.
    EDIT 2:
    Not so solved - worked for awhile, then suddenly stopped working, tried reinstalling all the modules again, restarting Bridge and now cannot repair the Facebook functionality. Submitting as bug, since only 'fix' is temporary and unreliable.
    Message was edited by: ficholasnorneris

  • HTTPS persistence SSL session, ACN 4.2.1

    Customer is experiencing a problem resulting in the ACN software resolving the host.domain.com twice. Webapplication https://host.domain.com/webapp/index.jsp. The customer uses a ACN to proxy the https request. The host.domain gets resolve to 1 of 4 available application servers (webserver). At the application login page (index.jsp) the user is successfully authenticated by the application's Login servlet on webserver 1. The user is then redirected to the select application, local to the webserver 1. It appears that when the ACN receives the response from webserver 1 with the fully qualitfying URL. The redirection cause the ACN to resolve the host.domain against DNS and as a result, the user's browser is redirected to a different webserver. The users previous session is no longer valid, breaking the client/webserver trusted relationship
    If the above user uses 1 of the 4 available IP address on the DNS entry, the users successfully maintains the SSL session. The customer is migrating to a Cisco Content Engine 560 running version 4.2.1 ACN software.
    I understand there are ACN features that could effect the HTTP session persistence/SSL trust. The services/features include boomerang, Reverse Proxy, content balancing. I request information on the service or feature of the ACN that could cause the problem I speak of from above.
    I understand there are different methods of implementing session persistence, like sticky session and SSL sticky, but believe the ACN does provide this feature.

    The customer is experiencing network issues when attempting to access our application. The customer is experiencing has been seen with a previous customers that had a similar network devices.
    The customer uses a Cisco Content Engine CE-560 with Application and Content Networking Software (ACNS) version 4.2.1. The problem seems to a result of the ACNS resolving the hostname.domain.com twice. The webserver's DNS (hostname.domain.com) entry resolves to one of four available webservers (DNS round robining).
    nslookup hostname.domain.com
    webserver1 webserver2 webserver3 webserver4
    nslookup hostname.domain.com
    webserver2 webserver3 webserver4 webserver1
    and so on.
    All client/webserver communication is through SSL. When the customer uses the FQDN URL (https://hostname.domain.com/webapp/index.jsp) to access the application login page, the server portion of the URL is resolved to webserver1. At this time, the customer has an established HTTPS session with webserver1. Once a login servlet running on webserver1, receives the customer supplied login credentials, the servlet sends a server response 302 redirecting the customer to the selected application.
    This redirection response seems to cause the ACNS to resolve the hostname.domain.com and as a result, the customer's browser is redirected to a different webserver, webserver2. The users previous session is no longer valid, causing the application to generate a false inactivity timeout.
    If the customer sends a HTTPS request using anyone of the four IP address from DNS, the session is maintained and the customer does not receive the false inactivity timeout, because the session is not "broken".
    The customer is migrating off of a Netscape (iPlanet) Web Proxy solution and does not experience the problem accessing the application, using the FQDN URL.
    DNS caching is enabled on the customer CE.

  • Unique session key  weblogic portal 9.2

    Hi,
    Is there a way I can generate unique session key to ensure correct session is tracking between every desktop with different user.
    Is this right way to handle session in weblogic portal 9.2?

    Hi
    what exactly do you want to do? A session does have an id which is guaranteed unique while the server is running (you dont need to do anything special for this). HttpSession.getId.
    Note However normally this value gets stored as a cookie on the browser (with the default name of JSESSIONID) and you must ensure that different webapps on the same domain dont overwrite this value
    regards
    deepak

  • Http.keepAlive does not turn off SSL session cache?

    Hi there,
    I have a web service client that uses JSSE for making web service calls via https. In an effort to debug problems, I set http.keepAlive to false, I can see from the SSL debug output that KeepAlive timer messages no longer shows up, but I still see text such as "Cached client session" and "try to reuse cached session", etc.
    Should not turning off keepAlive disable the use of persistent sessions?
    Thanks.
    Yan

    They are unrelated features.
    HTTP Keep Alive allows the browser to maintain a Socket to the server and issue multiple HTTP requests over that same socket.
    SSL Session caching is when an SSL Session is assigned an ID, and additional SSL connects may be established with the same ID. These additional sockets then do not need to perform the full SSL handshake, since much of the data has already been negotiated previously.

  • How to use Session Key-based Request Targeting Mechanism in OCCAS ??

    I read Session Key-Based Request Targeting(chapter 5) in Developing SIP Applications.
    But, I don't work my application using this mechanism.
    I add sesssionKey function with @SipApplicationKey annotation.
    I deploy this application. And then, other machine send INVITE request.
    My application received INVITE request. But sessionKey function is not called before doInvite function is called.
    I used @SipApplicationKey(applicationName="...") annotation.
    It didn't work.
    sample code is following.
    Could someone help me?
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.sip.SipFactory;
    import javax.servlet.sip.SipServlet;
    import javax.servlet.sip.SipServletMessage;
    import javax.servlet.sip.SipServletRequest;
    import javax.servlet.sip.SipServletResponse;
    import javax.servlet.sip.SipURI;
    import javax.servlet.sip.URI;
    import javax.servlet.sip.annotation.SipApplicationKey;
    public class app2SipServlet extends SipServlet {
    private static final long serialVersionUID = 1L;
    public static SipFactory sipFactory;
    public static ServletContext sc;
    public void init(ServletConfig cfg) throws ServletException {
    super.init(cfg);
    sipFactory = getSipFactory();
    sc = getServletContext();
    trace("+++ app2SipServlet Initialization");          
    @SipApplicationKey
    public static String sessionKey(SipServletRequest req) {
    String appid = req.getHeader("ApplicationID");
    System.out.println("application id : " + appid);
    return appid;
    @Override
    public void doRequest(SipServletRequest req)     throws ServletException, IOException {
    trace(req, "doRequest()");
    super.doRequest(req);
    @Override
    protected void doInvite(SipServletRequest req) throws ServletException, IOException {
    URI from = req.getFrom().getURI();
    String user = ((SipURI)from).getUser();
    trace(user + " : " + req.getSession().getApplicationSession().getId());
    trace(user + " : " + req.getSession().getApplicationSession().getApplicationName());
    SipServletResponse resp = req.createResponse(200);
    resp.send();
    trace(resp);
    }

    How many servlets you have defined in your sip.xml .If there are multiple you may want to check if
    -- You have defined main-servlet ?
    -- or Is deployment descriptor version 1.0 or 1.1

  • Disable non-SSL session tracking?

    Hi, all,
    I wonder if one can disable all session tracking in JSP's whenever SSL is not being used? I would like to turn off all cookie-setting and URL-rewriting and use SSL-session tracking only (if I use session-tracking at all on a given page). I also want to specify this behavior programmatically (inside my JSP's) and not in my server's config files.
    I'm basically concerned that if my user leaves one of my HTTPS pages, they will still retain a non-secure cookie with their session information. This seems to be indeed the default behavior: when I run my tests and transition from an HTTPS page to an HTTP one, the browser does store a cookie. I know I can invalidate the session as the next step, but I'd rather have the cookie not being set altogether to begin with. Imagine the situation where the user leaves my HTTPS page for a totally different (HTTP) website: in this setting I won't get a chance to invalidate the session and delete the cookie.
    Any ideas, therefore, on how to programmatically disable non-SSL session-tracking?
    Thanks,
    Dmitri.

    I don't think you can do this programatically.
    However I also don't think it is a problem.
    Cookies are related to zone names aren't they?
    http://mysite and https://mysite are two different
    zones as far as cookies are concerned. One should
    not be able to see the other.
    It issues a new cookie for the http site you are just
    navigating to. That cookie has nothing to do with
    the secure site you just came from, and shouldn't be
    able to tell them any info about the secure site.
    I think you are worrying about something that isn't
    really there.
    What is your concern? That they pick up a JSESSIONID
    from the cookie and can then pretend to be a
    different user?Yes. A cookie is transmitted and stored unencrypted, I imagine (in any case, it should be more easily crackable than SSL). I wish Sun came up with an extension to the Session API where you would be able to explicitly specify which session-tracking protocols you want used and which ones you don't. At the moment their API abstracts and manages too much detail for you.
    I mean, if my site is supposed to be secure while I'm using SSL, then you'd expect that no information about those secure sessions should leak outside the SSL protocol, wouldn't you say?

  • SSL Session cache persistence

    Hello,
    I've been scratching my head for while on a problem concerning SSL session caching. Upon examining memory usage of the session cache I noticed that the number of cached sessions is reset at some point while new session are created. For example sometimes at around 300 -1500 sessions the number drops to under 10. I have set the session cache size to unlimited (via SSLSessionContext.setSessionCacheSize()) and session timeout to 24 hours (via setSessionTimeout()).
    I noticed that this has probably something to do with garbage collection. I made a server application that receives SSL connections and every few seconds prints the number sessions in the cache and the amount of consumed memory (in megs). I also enabled garbace collection information printing and ran java VM with a maximum heap size of 512M. I ran a client application against it that continuously initializes a new sessions. Here's what I got:
    Sessions: 484     Memory: 1.7913589477539062
    [GC [DefNew: 503K->4K(576K), 0.0007350 secs] 2234K->1734K(3796K), 0.0008700 secs]
    [GC [DefNew: 513K->63K(576K), 0.0009260 secs] 2243K->1793K(3796K), 0.0010680 secs]
    Sessions: 490     Memory: 1.7832870483398438
    [GC [DefNew: 569K->37K(576K), 0.0021150 secs] 2299K->1773K(3796K), 0.0022560 secs]
    Sessions: 495     Memory: 2.1244659423828125
    [GC [DefNew: 543K->37K(576K), 0.0019000 secs] 2279K->1775K(3796K), 0.0034750 secs]
    [GC [DefNew: 549K->57K(576K), 0.0009080 secs] 2287K->1796K(3796K), 0.0010290 secs]
    [Full GC [Tenured: 1739K->1635K(3220K), 0.0865340 secs] 1962K->1635K(3796K), [Perm : 3267K->3267K(8192K)], 0.0885000 secs]
    Sessions: 6     Memory: 1.7752304077148438
    [GC [DefNew: 512K->58K(576K), 0.0016310 secs] 2147K->1694K(3796K), 0.0017680 secs]
    [GC [DefNew: 568K->37K(576K), 0.0009750 secs] 2204K->1678K(3796K), 0.0011110 secs]
    Sessions: 12     Memory: 1.7010269165039062
    [GC [DefNew: 549K->56K(576K), 0.0014310 secs] 2190K->1699K(3796K), 0.0015600 secs]Notice how the number of sessions drops from 495 to 6? And in between there's a garbage collection print "[Full GC...". Why is this? Shouldn't the session cache keep the sessions until there's either too many of the them or they get too old? Here only a few minutes have elapsed and memory consumption is under control (1 to 3 megs).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    In my implementation I avoid session renegotiation as
    much as possible to achieve high throughput. My goal
    is to preserve sessions for the entire session
    timeout time. This raises a few questions:Understood, but you also have to protect the server against resource exhaustion. It's in the client's interest to cache lots of sessions for a long time; the server's interest is to conserve resources so it can keep itself running.
    You actually don't want to cache all the sessions, just the 'hot' ones, so you're better off having the SessionContext remove sessions on an LRU basis by having a finite limit, rather than just letting them be GC'd. The fact that so many sessions were collected in your runs indicates pretty severe memory usage.
    (1) Is there any way to tweak this behavior? For
    example can make the sessions live longer by using
    some GC flags for the VM? Allocate more heap space, or cache fewer sessions.
    (2) How about keeping regular references to all the
    sessions in my application?That would save them from GC of course. But then you'll quickly discover that you really do need a finite limit.
    (3) Is the behavior of the session cache or the inner
    workings of the SSL API in general documented
    somewhere?Only in the source code of JSSE, and that's only a property of Sun's JRE implementation. Session caching is not even a required feature, and J2ME implementations for example generally don't do it at all.

  • JAAS, EJB, GlassFish2 and session key/id

    I use standalone EJB client to connect to GlassFish 2. I use custom login module on Aplication server side and ProgrammaticLogin to enter login and password.
    I see that every call to any of my remote methods is resulted in sending my login and password to Application server (to my login module).
    I do not want it sends login/password every time but only first time. I’d like to do smth as it is done in http session.
    I’d like to send login and password only once when I lookup my remote interface or when I do explicit login. Then if authentication is successes I’ve got smth like session key/id and use it for client identification.
    How I can implement it? How I can send session key back to client on successful login? Is it possible at all in JAAS/EJB world?

    I think there's something wrong with your application. Have you checked google? There's plenty of threads about this same problem here already please refer to them. Please copy paste your whole stacktrace here, we experts can't help you otherwise.
    Best Regards, Angus

  • CSS11503/ACE 4710 - SSL session id cache

    I have a couple of questions.
    1. I'd like to know what happens when the SSL session id cache (def 10k) gets filled on a CSS11503. Do new connections get dropped or do they still work but are they less efficient?
    2. What is the cache size on an ACE4710?

    The problem was caused by an incorrect nat pool.   Correct Mask was 255.255.255.0.

  • Session key can not help in RSA?

    Hello, I used session key (des) in RSA public key encryption, but it still have the same problem, and the code here, anybody help,,please. thanks very much
                 //prepare for encryption
                  ecipherDES = Cipher.getInstance("des");
                  ecipherDES.init(Cipher.ENCRYPT_MODE, sessionKey);
                 so1 = new SealedObject(si, ecipherDES);
                // prepare encryption
                  ecipherRSA = Cipher.getInstance("RSA");
                  ecipherRSA.init(Cipher.ENCRYPT_MODE, pair.getPublic());
                 so2 = new SealedObject(sessionKey, ecipherRSA);

    Hello, I used session key (des) in RSA public key
    encryption, but it still have the same problem, and
    the code here, anybody help,,please. thanks very
    much
         //prepare for encryption
    ipherDES = Cipher.getInstance("des");
    ecipherDES.init(Cipher.ENCRYPT_MODE,
    E, sessionKey);
         so1 = new SealedObject(si, ecipherDES);
    // prepare encryption
    ipherRSA = Cipher.getInstance("RSA");
    ecipherRSA.init(Cipher.ENCRYPT_MODE,
    E, pair.getPublic());
    so2 = new SealedObject(sessionKey, ecipherRSA);
    Rather than RSA the whole DES SecretKey (this takes with it a whole load of baggage you don't need) you should RSA just the bytes (secretKey.getEncoded()) of the session key. You can then reconstruct the DES SecretKey from the bytes extracted from the sealed object.
    SecretKey key = new SecretKeySpec(sessionKeyBytes, "DES");
    P.S. Though this ue of sealed objects seems an easy approach I don't like it because the result cannot (easily) be decrypted outside of Java.

Maybe you are looking for

  • Have 2 ipod but windows will not accept my new ipod shuffle!

    I aleady have a ipod mini set up on my computer which is fine,i have also now got a ipod suffle wich windows xp is saying that it has found a new divice but when i go to install it it says that it is not windows logo tested and that i sould stop the

  • Java Mapping Error - Unable to instantiate the Java class

    Hi, I am trying out a Java Mapping scenario. The code worked fine in eclipse.i could get the desired output. but when i tried it out in XI ....i got the following error in moni: *Unable to instantiate the Java class* <?xml version="1.0" encoding="UTF

  • Emailing report through CMS (ScheduleToSMTP) - Need Multi-format support

    Hi All, I have implemented the ScheduleToSMTP method for sending my crystal report as an email attachment to the users. This has been done as described in the below link(s): http://devlibrary.businessobjects.com/businessobjectsxi/en/en/BOE_SDK/boesdk

  • A question to Denes Kubicek (Repeating Calendar)

    Hi Denes! I've an issue with the calendar function you've posted on the blog...I was using it preety much and it was working fine until I've modified it with some if clauses... It looks like this now... create or replace FUNCTION return_table_fn RETU

  • Trying to add Custom Label to iPad contacts

    I can find the Add Custom Label in the list of labels through contact - edit.  I can type in a new Custom Label  - but there is just no way to save it.  Tearing out what little hair I have.  Any advice appreciated.