Ignore:
Timestamp:
2014-11-29T20:52:09+01:00 (10 years ago)
Author:
donvip
Message:

[josm_trustosm] update to Bouncy Castle 1.51

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/util/TrustGPG.java

    r30744 r30829  
    1919import java.security.NoSuchAlgorithmException;
    2020import java.security.NoSuchProviderException;
     21import java.security.Provider;
    2122import java.security.SecureRandom;
    2223import java.security.Security;
     
    4748import javax.swing.SpringLayout;
    4849
     50import org.bouncycastle.bcpg.HashAlgorithmTags;
    4951import org.bouncycastle.bcpg.sig.NotationData;
    5052import org.bouncycastle.jce.provider.BouncyCastleProvider;
     
    6567import org.bouncycastle.openpgp.PGPSignatureSubpacketVector;
    6668import org.bouncycastle.openpgp.PGPUtil;
     69import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
     70import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
     71import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder;
     72import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider;
     73import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
     74import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider;
     75import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
     76import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
     77import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
     78import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
     79import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
     80import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
    6781import org.bouncycastle.util.encoders.Hex;
    6882import org.openstreetmap.josm.Main;
     
    534548            }
    535549
    536             PGPPrivateKey pgpPrivKey = pgpSecKey.extractPrivateKey(password, "BC");
    537             PGPSignatureGenerator sGen = new PGPSignatureGenerator(pgpSecKey.getPublicKey().getAlgorithm(), digest, "BC");
    538             sGen.initSign(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey);
     550            Provider provider = Security.getProvider("BC");
     551            PGPDigestCalculatorProvider digestCalculatorProvider = new JcaPGPDigestCalculatorProviderBuilder().setProvider(provider).build();
     552            PBESecretKeyDecryptor secretKeyDecryptor = new JcePBESecretKeyDecryptorBuilder(digestCalculatorProvider).setProvider(provider).build(password);
     553            PGPPrivateKey pgpPrivKey = pgpSecKey.extractPrivateKey(secretKeyDecryptor);
     554            int keyAlgorithm = pgpSecKey.getPublicKey().getAlgorithm();
     555            PGPContentSignerBuilder contentSignerBuilder = new JcaPGPContentSignerBuilder(keyAlgorithm, digest).setProvider(provider).setDigestProvider(provider);
     556            PGPSignatureGenerator sGen = new PGPSignatureGenerator(contentSignerBuilder);
     557            sGen.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey);
    539558
    540559            Iterator<?> it = pgpSecKey.getPublicKey().getUserIDs();
     
    575594    }*/
    576595        try {
    577             sig.initVerify(pgpPub.getPublicKey(sig.getKeyID()), "BC");
     596            Provider provider = Security.getProvider("BC");
     597            PGPContentVerifierBuilderProvider contentVerifierBuilderProvider = new JcaPGPContentVerifierBuilderProvider().setProvider(provider);
     598            sig.init(contentVerifierBuilderProvider, pgpPub.getPublicKey(sig.getKeyID()));
    578599            sig.update(sigtext.getBytes(Charset.forName("UTF-8")));
    579600            return sig.verify();
     
    812833
    813834        Date now = new Date();
    814         PGPKeyPair pgpKp = new PGPKeyPair(al, kp, now);
     835        PGPKeyPair pgpKp = new JcaPGPKeyPair(al, kp, now);
    815836
    816837        getPasswordfromUser();
     
    825846        }
    826847
    827         PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, pgpKp,
    828                 userId.getText(), protAl[protectBox.getSelectedIndex()], password, true, subPck, null, new SecureRandom(), "BC");
     848        Provider provider = Security.getProvider("BC");
     849        int encAlgorithm = protAl[protectBox.getSelectedIndex()];
     850        PGPDigestCalculator checksumCalculator = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
     851        PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder(pgpKp.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1);
     852        PBESecretKeyEncryptor encryptor = new JcePBESecretKeyEncryptorBuilder(encAlgorithm).setProvider(provider).
     853                setSecureRandom(new SecureRandom()).build(password);
     854       
     855        PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, pgpKp, userId.getText(),
     856                checksumCalculator, subPck, null, signerBuilder, encryptor);
    829857
    830858        if (pgpPub == null) {
Note: See TracChangeset for help on using the changeset viewer.