Java Code Examples for org.opensaml.xml.security.credential.Credential#getSecretKey()

The following examples show how to use org.opensaml.xml.security.credential.Credential#getSecretKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicProviderKeyInfoCredentialResolver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Utility method to extract any key that might be present in the specified Credential.
 * 
 * @param cred the Credential to evaluate
 * @return the Key contained in the credential, or null if it does not contain a key.
 */
protected Key extractKeyValue(Credential cred) {
    if (cred == null) {
        return null;
    }
    if (cred.getPublicKey() != null) {
        return cred.getPublicKey();
    }
    // This could happen if key is derived, e.g. key agreement, etc
    if (cred.getSecretKey() != null) {
        return cred.getSecretKey();
    }
    // Perhaps unlikely, but go ahead and check
    if (cred.getPrivateKey() != null) {
        return cred.getPrivateKey();
    }
    return null;
}
 
Example 2
Source File: AbstractKeyInfoProvider.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Utility method to extract any key that might be present in the specified Credential.
 * 
 * @param cred the Credential to evaluate
 * @return the Key contained in the credential, or null if it does not contain a key.
 */
protected Key extractKeyValue(Credential cred) {
    if (cred == null) {
        return null;
    }
    if (cred.getPublicKey() != null) {
        return cred.getPublicKey();
    } 
    // This could happen if key is derived, e.g. key agreement, etc
    if (cred.getSecretKey() != null) {
        return cred.getSecretKey();
    }
    // Perhaps unlikely, but go ahead and check
    if (cred.getPrivateKey() != null) {
        return cred.getPrivateKey(); 
    }
    return null;
}
 
Example 3
Source File: SecurityHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Extract the encryption key from the credential.
 * 
 * @param credential the credential containing the encryption key
 * @return the encryption key (either a public key or a secret (symmetric) key
 */
public static Key extractEncryptionKey(Credential credential) {
    if (credential == null) {
        return null;
    }
    if (credential.getPublicKey() != null) {
        return credential.getPublicKey();
    } else {
        return credential.getSecretKey();
    }
}
 
Example 4
Source File: SecurityHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Extract the decryption key from the credential.
 * 
 * @param credential the credential containing the decryption key
 * @return the decryption key (either a private key or a secret (symmetric) key
 */
public static Key extractDecryptionKey(Credential credential) {
    if (credential == null) {
        return null;
    }
    if (credential.getPrivateKey() != null) {
        return credential.getPrivateKey();
    } else {
        return credential.getSecretKey();
    }
}
 
Example 5
Source File: SecurityHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Extract the signing key from the credential.
 * 
 * @param credential the credential containing the signing key
 * @return the signing key (either a private key or a secret (symmetric) key
 */
public static Key extractSigningKey(Credential credential) {
    if (credential == null) {
        return null;
    }
    if (credential.getPrivateKey() != null) {
        return credential.getPrivateKey();
    } else {
        return credential.getSecretKey();
    }
}
 
Example 6
Source File: SecurityHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Extract the verification key from the credential.
 * 
 * @param credential the credential containing the verification key
 * @return the verification key (either a public key or a secret (symmetric) key
 */
public static Key extractVerificationKey(Credential credential) {
    if (credential == null) {
        return null;
    }
    if (credential.getPublicKey() != null) {
        return credential.getPublicKey();
    } else {
        return credential.getSecretKey();
    }
}
 
Example 7
Source File: ExplicitKeyTrustEvaluator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Evaluate trust.
 * 
 * @param untrustedCredential the untrusted credential to evaluate
 * @param trustedCredential basis for trust
 * @return true if trust can be established, false otherwise
 */
public boolean validate(Credential untrustedCredential, Credential trustedCredential) {

    Key untrustedKey = null;
    Key trustedKey = null;
    if (untrustedCredential.getPublicKey() != null) {
        untrustedKey = untrustedCredential.getPublicKey();
        trustedKey = trustedCredential.getPublicKey();
    } else {
        untrustedKey = untrustedCredential.getSecretKey();
        trustedKey = trustedCredential.getSecretKey();
    }
    if (untrustedKey == null) {
        log.debug("Untrusted credential contained no key, unable to evaluate");
        return false;
    } else if (trustedKey == null) {
        log.debug("Trusted credential contained no key of the appropriate type, unable to evaluate");
        return false;
    }

    if (validate(untrustedKey, trustedKey)) {
        log.debug("Successfully validated untrusted credential against trusted key");
        return true;
    }

    log.debug("Failed to validate untrusted credential against trusted key");
    return false;
}
 
Example 8
Source File: EvaluableKeyLengthCredentialCriteria.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the key contained within the credential.
 * 
 * @param credential the credential containing a key
 * @return the key from the credential
 */
private Key getKey(Credential credential) {
    if (credential.getPublicKey() != null) {
        return credential.getPublicKey();
    } else if (credential.getSecretKey() != null) {
        return credential.getSecretKey();
    } else if (credential.getPrivateKey() != null) {
        // There should have been a corresponding public key, but just in case...
        return credential.getPrivateKey();
    } else {
        return null;
    }

}
 
Example 9
Source File: EvaluableKeyAlgorithmCredentialCriteria.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the key contained within the credential.
 * 
 * @param credential the credential containing a key
 * @return the key from the credential
 */
private Key getKey(Credential credential) {
    if (credential.getPublicKey() != null) {
        return credential.getPublicKey();
    } else if (credential.getSecretKey() != null) {
        return credential.getSecretKey();
    } else if (credential.getPrivateKey() != null) {
        // There should have been a corresponding public key, but just in case...
        return credential.getPrivateKey();
    } else {
        return null;
    }

}
 
Example 10
Source File: LocalKeyInfoCredentialResolver.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Determine whether the credential is a local credential.
 * 
 * A local credential will have either a private key or a secret (symmetric) key.
 * 
 * @param credential the credential to evaluate
 * @return true if the credential has either a private or secret key, false otherwise
 */
protected boolean isLocalCredential(Credential credential) {
    return credential.getPrivateKey() != null || credential.getSecretKey() != null;
}