Example usage for java.security GeneralSecurityException GeneralSecurityException

List of usage examples for java.security GeneralSecurityException GeneralSecurityException

Introduction

In this page you can find the example usage for java.security GeneralSecurityException GeneralSecurityException.

Prototype

public GeneralSecurityException(Throwable cause) 

Source Link

Document

Creates a GeneralSecurityException with the specified cause and a detail message of (cause==null ?

Usage

From source file:hudson.cli.CLI.java

/**
 * Authenticate ourselves against the server.
 *
 * @return//from  w  w w.j a v a2 s.co  m
 *      identity of the server represented as a public key.
 * @deprecated Specific to {@link Mode#REMOTING}.
 */
@Deprecated
public PublicKey authenticate(Iterable<KeyPair> privateKeys) throws IOException, GeneralSecurityException {
    Pipe c2s = Pipe.createLocalToRemote();
    Pipe s2c = Pipe.createRemoteToLocal();
    entryPoint.authenticate("ssh", c2s, s2c);
    Connection c = new Connection(s2c.getIn(), c2s.getOut());

    try {
        byte[] sharedSecret = c.diffieHellman(false).generateSecret();
        PublicKey serverIdentity = c.verifyIdentity(sharedSecret);

        // try all the public keys
        for (KeyPair key : privateKeys) {
            c.proveIdentity(sharedSecret, key);
            if (c.readBoolean())
                return serverIdentity; // succeeded
        }
        if (privateKeys.iterator().hasNext())
            throw new GeneralSecurityException("Authentication failed. No private key accepted.");
        else
            throw new GeneralSecurityException("No private key is available for use in authentication");
    } finally {
        c.close();
    }
}

From source file:com.zotoh.crypto.CryptoUte.java

private static SMIMESignedGenerator makeSignerGentor(PrivateKey key, Certificate[] certs, SigningAlgo algo)
        throws CertStoreException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
        GeneralSecurityException, CertificateEncodingException {

    SMIMESignedGenerator gen = new SMIMESignedGenerator("base64");
    List<Certificate> lst = asList(true, certs);

    ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
    SMIMECapabilityVector caps = new SMIMECapabilityVector();

    caps.addCapability(SMIMECapability.dES_EDE3_CBC);
    caps.addCapability(SMIMECapability.rC2_CBC, 128);
    caps.addCapability(SMIMECapability.dES_CBC);

    signedAttrs.add(new SMIMECapabilitiesAttribute(caps));

    X509Certificate x0 = (X509Certificate) certs[0];
    X509Certificate issuer = x0;/*  w ww  .j a va  2s  .c o m*/
    X500Principal issuerDN;

    if (certs.length > 1) {
        issuer = (X509Certificate) certs[1];
    }

    issuerDN = issuer.getSubjectX500Principal();
    x0 = (X509Certificate) certs[0];

    //
    // add an encryption key preference for encrypted responses -
    // normally this would be different from the signing certificate...
    //

    IssuerAndSerialNumber issAndSer = new IssuerAndSerialNumber(X500Name.getInstance(issuerDN.getEncoded()),
            x0.getSerialNumber());
    Provider prov = Crypto.getInstance().getProvider();

    signedAttrs.add(new SMIMEEncryptionKeyPreferenceAttribute(issAndSer));

    try {
        JcaSignerInfoGeneratorBuilder bdr = new JcaSignerInfoGeneratorBuilder(
                new JcaDigestCalculatorProviderBuilder().setProvider(prov).build());
        bdr.setDirectSignature(true);

        ContentSigner cs = new JcaContentSignerBuilder(algo.toString()).setProvider(prov).build(key);

        bdr.setSignedAttributeGenerator(
                new DefaultSignedAttributeTableGenerator(new AttributeTable(signedAttrs)));

        gen.addSignerInfoGenerator(bdr.build(cs, x0));
        gen.addCertificates(new JcaCertStore(lst));

        return gen;
    } catch (OperatorCreationException e) {
        throw new GeneralSecurityException(e);
    }
}

From source file:org.globus.gsi.gssapi.GlobusGSSContextImpl.java

protected void verifyDelegatedCert(X509Certificate certificate) throws GeneralSecurityException {
    RSAPublicKey pubKey = (RSAPublicKey) certificate.getPublicKey();
    RSAPrivateKey privKey = (RSAPrivateKey) this.keyPair.getPrivate();

    if (!pubKey.getModulus().equals(privKey.getModulus())) {
        throw new GeneralSecurityException(i18n.getMessage("keyMismatch"));
    }/* w w  w  .  j av a2 s .co  m*/
}