SoftwareSmartcard implements Smartcard, Serializable { @Override public SmartcardStatusCode storeCredential(int pin, URI credentialId, Credential cred, CredentialSerializer serializer){ byte[] credBytes = serializer.serializeCredential(cred); log.fine("CredBytes length: " + credBytes.length); int nextCredBlobUri = 1; SmartcardStatusCode returnCode = SmartcardStatusCode.OK; int bytesLeft = credBytes.length; int i = 0; boolean done = false; while(!done){ SmartcardBlob blob = new SmartcardBlob(); if(bytesLeft > MAX_BLOB_LEN_BYTES){ blob.blob = new byte[MAX_BLOB_LEN_BYTES]; bytesLeft -= MAX_BLOB_LEN_BYTES; System.arraycopy(credBytes, i*MAX_BLOB_LEN_BYTES, blob.blob, 0, MAX_BLOB_LEN_BYTES); }else{ blob.blob = new byte[bytesLeft]; System.arraycopy(credBytes, i*MAX_BLOB_LEN_BYTES, blob.blob, 0, bytesLeft); done = true; } URI credUri = URI.create(credentialId.toASCIIString()+"_"+nextCredBlobUri++); log.fine("storing a blob of size: " + blob.blob.length + " with uri: " + credUri.toASCIIString()); returnCode = this.storeBlob(pin, credUri, blob); log.fine("Return from storeBlob: " + returnCode); if(returnCode != SmartcardStatusCode.OK){ return returnCode; } i++; } return returnCode; } SoftwareSmartcard();  SoftwareSmartcard(Random random); @Override SmartcardStatusCode changePin(int pin, int newPin); @Override SmartcardStatusCode deleteBlob(int pin, URI uri); @Override SmartcardStatusCode deleteCredential(int pin, URI credentialUri); @Override void removeCredentialUri(int pin, URI uri); @Override SmartcardBlob getBlob(int pin, URI uri); @Override Map<URI, SmartcardBlob> getBlobs(int pin); @Override Set<URI> getBlobUris(int pin); @Override Course getCourse(int pin, URI issuerUri); @Override byte[] getNewNonceForSignature(); @Override SmartcardStatusCode incrementCourseCounter(int pin, RSAKeyPair key,
            URI issuerUri, int lectureId); @Override Set<Course> listCourses(int pin); @Override int pinTrialsLeft(); @Override int pukTrialsLeft(); @Override SmartcardStatusCode resetPinWithPuk(int puk, int newPin); @Override boolean smartcardPresent(); @Override SmartcardStatusCode storeBlob(int pin, URI uri, SmartcardBlob blob); @Override boolean wasInit(); @Override int init(int newPin, SystemParameters sysParams,
            RSAKeyPair rootKey, short deviceID); @Override URI getDeviceURI(int pin); @Override short getDeviceID(int pin); @Override RSAVerificationKey readAuthenticationKey(int pin, int keyID); @Override SystemParameters getSystemParameters(int pin); @Override BigInteger computeScopeExclusivePseudonym(int pin, URI scope); @Override BigInteger computeDevicePublicKey(int pin); @Override ZkProofCommitment prepareZkProof(int pin, Set<URI> credentialIds,
            Set<URI> scopeExclusivePseudonyms, boolean includeDevicePublicKeyProof); @Override ZkProofResponse finalizeZkProof(int pin, BigInteger challenge, Set<URI> credentialIds,
            Set<URI> scopeExclusivePseudonyms); @Override SmartcardBackup backupAttendanceData(int pin, String password); @Override SmartcardStatusCode restoreAttendanceData(int pin, String password,
            SmartcardBackup backup); @Override BigInteger computeCredentialFragment(int pin, URI credentialUri); @Override Set<URI> listCredentialsUris(int pin); @Override TrustedIssuerParameters getIssuerParametersOfCredential(int pin, URI credentialUri); @Override SmartcardStatusCode storeCredential(int pin, URI credentialId, Credential cred, CredentialSerializer serializer); @Override SmartcardStatusCode storePseudonym(int pin, URI pseudonymId, PseudonymWithMetadata pseudo, PseudonymSerializer serializer); @Override PseudonymWithMetadata getPseudonym(int pin, URI pseudonymId, PseudonymSerializer serializer); @Override SmartcardStatusCode deletePseudonym(int pin, URI pseudonymUri); @Override Credential getCredential(int pin, URI credentialId, CredentialSerializer serializer); @Override SmartcardStatusCode allocateCredential(int pin, URI credentialUri, URI issuerParameters); @Override SmartcardStatusCode addIssuerParametersWithAttendanceCheck(RSAKeyPair rootKey,
            URI parametersUri, int keyIDForCounter, SmartcardParameters credBases,
            RSAVerificationKey courseKey, int minimumAttendance); @Override SmartcardStatusCode addIssuerParameters(RSAKeyPair rootKey,
            URI parametersUri, SmartcardParameters credBases); @Override TrustedIssuerParameters getIssuerParameters(int pin, URI paramsUri); @Override Set<TrustedIssuerParameters> getIssuerParametersList(int pin); @Override SmartcardStatusCode deleteIssuer(int pin, URI paramUri, RSAKeyPair rootKey); @Override boolean credentialExists(int pin, URI credentialUri); @Override int getCounterValue(int pin, URI issuerId); String getHashOfDeviceSecret(); String getHashOfSystemParameters(); String getHashOfIssuerParameters(); String getHashOfCredentialKeys();  }
@Test public void testStoreCredential(){ SoftwareSmartcard s = setupSmartcard(); Random r = new Random(1234); URI longURI1 = URI.create(new BigInteger(2048*3, r).toString()); URI longURI2 = URI.create(new BigInteger(2048*2, r).toString()); URI longURI3 = URI.create(new BigInteger(2048*2, r).toString()); System.out.println("credUID: " + longURI3); byte[] loongByteArr = new byte[2048*2+256]; Credential cred = new Credential(); CryptoParams cryptoParam = new CryptoParams(); CredentialDescription credDesc = new CredentialDescription(); credDesc.setImageReference(ImagePathBuilder.TEST_IMAGE_JPG); credDesc.setIssuerParametersUID(longURI2); credDesc.setCredentialSpecificationUID(longURI2); credDesc.setCredentialUID(longURI3); cred.setCredentialDescription(credDesc); cred.setCryptoParams(cryptoParam); URI credentialId = URI.create("credUri"); s.storeCredential(pin, credentialId, cred, serializer); Credential credPrime = s.getCredential(pin, credentialId, serializer); CredentialDescription credDescriptionPrime = credPrime.getCredentialDescription(); System.out.println("from read credential - credUID: "+credDescriptionPrime.getCredentialUID().toString()); assertEquals(credDesc.getCredentialUID(), credDescriptionPrime.getCredentialUID()); byte[] origCredSerialized = serializer.serializeCredential(cred); byte[] newCredSerialized = serializer.serializeCredential(credPrime); System.out.println("orig: " + origCredSerialized.length+", new: " + newCredSerialized.length); assertTrue(Arrays.equals(origCredSerialized, newCredSerialized)); PseudonymWithMetadata pseudonym = new PseudonymWithMetadata(); Pseudonym pseu = new Pseudonym(); pseu.setExclusive(true); URI pseudonymUID = URI.create("pseudonymUri"); pseu.setPseudonymUID(pseudonymUID); pseu.setPseudonymValue(loongByteArr); pseu.setScope("testScope"); pseu.setSecretReference(deviceURI); pseudonym.setPseudonym(pseu); pseudonym.setCryptoParams(cryptoParam); CardStorage cardStorage = new CardStorage(); cardStorage.addSmartcard(s, pin); PseudonymSerializer pseudonymSerializer = new PseudonymSerializerGzipXml(cardStorage); System.out.println("After this line"); s.storePseudonym(pin, pseudonymUID, pseudonym, pseudonymSerializer); PseudonymWithMetadata pseudonymPrime = s.getPseudonym(pin, pseu.getPseudonymUID(), pseudonymSerializer); byte[] first = pseudonymSerializer.serializePseudonym(pseudonym); byte[] second = pseudonymSerializer.serializePseudonym(pseudonymPrime); assertTrue(Arrays.equals(first, second)); }