constructorcryptographyappletsmartcardjavacard

Why is my ACOSJ Javacard applet failing to install?


I'm writing an applet for an ACOSJ card in JCIDE and I keep getting the error message: 'Install Applet failed' with the response APDU 69 85.

This is my install method

    public static void install(byte[] bArray, short bOffset, byte bLength) 
    {
        new ACOSJSigMem().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
    }

And this is my constructor

    private ACOSJSigMem() {
        
        //set up key
        key = new KeyPair(KeyPair.ALG_EC_FP, KeyBuilder.LENGTH_EC_FP_256);
        key.genKeyPair();
        pubKey = (ECPublicKey) key.getPublic();
        privKey = (ECPrivateKey) key.getPrivate();
        
        //set up public key parameters
        pubKey.setFieldFP(SECP256R1_FP, (short)0, (short)SECP256R1_FP.length); //set the values
        pubKey.setA(SECP256R1_A, (short)0, (short)SECP256R1_A.length);
        pubKey.setB(SECP256R1_B, (short)0, (short)SECP256R1_B.length);
        pubKey.setG(SECP256R1_G, (short)0, (short)SECP256R1_G.length);
        pubKey.setR(SECP256R1_R, (short)0, (short)SECP256R1_R.length);
        pubKey.setK(SECP256K1_K);
        
        //set up private key parameters
        privKey.setFieldFP(SECP256R1_FP, (short)0, (short)SECP256R1_FP.length); //set the values
        privKey.setA(SECP256R1_A, (short)0, (short)SECP256R1_A.length);
        privKey.setB(SECP256R1_B, (short)0, (short)SECP256R1_B.length);
        privKey.setG(SECP256R1_G, (short)0, (short)SECP256R1_G.length);
        privKey.setR(SECP256R1_R, (short)0, (short)SECP256R1_R.length);
        privKey.setK(SECP256K1_K);
        
        ecPublicKey = (ECPublicKey) key.getPublic();
        publicKeyLen = ecPublicKey.getW(keyArr, (short)0);

        
    }

I think it is the publicKeyLen = ecPublicKey.getW(keyArr, (short)0); line that is causing the problem but I'm not sure why.


Solution

  • In this case it was because I hadn't initialised the keyArr byte array in a method before using it.