|
From: Martin P. <Mar...@ia...> - 2008-01-22 09:47:41
|
Hi...
Maksim Djackov wrote:
> - How can I verify the result of TcIRsaKey.certifyKey() (certify the
> BIND public key with the AIK private key) command on the other machine,
> given the AIK public key and the BIND public key?
The signature verification stuff works about like this...
(from memory, not tested, may be buggy)
TPM machine:
TcTssValidation certifyResult = bindKey.certifyKey(identityKey, ....);
... = certifyResult.getData(); // plain data
... = certifyResult.getValidationData(); // signature
TcBlobData pubBlob = identitykey.getAttribData(TcTssDefines.TSS_TSPATTRIB_KEY_BLOB, TcTssDefines.TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY);
TcTcpaPubkey pubStruct = new TcTcpaPubkey(pubBlob);
... = pubStruct.getPubKey().getKey(); // public key
Verifier side:
byte[] aikPubBytes,
byte[] signatureBytes,
byte[] plainDataBytes,
TcBlobData pubKeyBlob = TcBlobData.newByteArray(aikPubBytes);
TcBlobData certifySignature = TcBlobData.newByteArray(signatureBytes);
TcBlobData plainData = TcBlobData.newByteArray(plainDataBytes);
pubKeyBlob.prepend(TcBlobData.newBYTE(((byte) 0))); // BigInteger requires a leading sign-byte
RSAPublicKeySpec pubEkSpec = new RSAPublicKeySpec(new BigInteger(pubKeyBlob.asByteArray()),new BigInteger("65537")); // 65537 is TPM default
RSAPublicKey pubKeyJava = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(pubEkSpec);
TcIContext context = new TcTssLocalCallFactory().newContextObject();
// do not connect context, we need no TPM (only possible with IAIK stack)
TcTpmPubkey pubAikStruct = TcCrypto.pubJavaToTpmKey(pubKeyJava);
TcIRsaKey pubAik = context.createRsaKeyObject(TcTssConstants.TSS_KEY_EMPTY_KEY);
pubAik.setAttribData(TcTssConstants.TSS_TSPATTRIB_KEY_BLOB, TcTssConstants.TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY, pubAikStruct.getEncoded());
// hmmm... maybe not needed, already set by pubJavaToTpmKey?
pubAik.setAttribUint32(TcTssConstants.TSS_TSPATTRIB_KEY_INFO, TcTssConstants.TSS_TSPATTRIB_KEYINFO_ENCSCHEME, TcTssConstants.TSS_ES_NONE);
pubAik.setAttribUint32(TcTssConstants.TSS_TSPATTRIB_KEY_INFO, TcTssConstants.TSS_TSPATTRIB_KEYINFO_SIGSCHEME, TcTssConstants.TSS_SS_RSASSAPKCS1V15_SHA1);
// do signature verify
TcIHash hash = context.createHashObject(TcTssConstants.TSS_HASH_SHA1);
hash.setHashValue(certifySignature.sha1());
hash.verifySignature(plainData, pubAik);
TODO: check actual content CERTIFY_INFO if as expected
> However, I have another question now as well. This is regarding using
> the public portion of the key created in the TPM to encrypt information
> on another machine and decrypt information later on the TPM where the
> key was created using the private portion of the key.
Errr... I don't think I've ever thought about that...
HTH,
Martin
|