Example #1
0
        /// <returns>True for success, false for error (where this has called onError).</returns>
        internal bool decryptAndImportKdk(Data kdkData,
                                          EncryptError.OnError onError_0)
        {
            try {
                logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "Decrypting and importing KDK {0}",
                            kdkData.getName());
                EncryptedContent encryptedContent_1 = new EncryptedContent();
                encryptedContent_1.wireDecodeV2(kdkData.getContent());

                SafeBag safeBag = new SafeBag(encryptedContent_1.getPayload());
                Blob    secret  = keyChain_.getTpm().decrypt(
                    encryptedContent_1.getPayloadKey().buf(),
                    credentialsKey_.getName());
                if (secret.isNull())
                {
                    onError_0.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.TpmKeyNotFound,
                                      "Could not decrypt secret, "
                                      + credentialsKey_.getName().toUri()
                                      + " not found in TPM");
                    return(false);
                }

                internalKeyChain_.importSafeBag(safeBag, secret.buf());
                return(true);
            } catch (Exception ex) {
                // This can be EncodingException, Pib.Error, Tpm.Error, or a bunch of
                // other runtime-derived errors.
                onError_0.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.DecryptionFailure,
                                  "Failed to decrypt KDK [" + kdkData.getName().toUri()
                                  + "]: " + ex);
                return(false);
            }
        }