Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Bouncy Castle 1.51 removes the PGPSecretKey.extractPrivateKey(String) #6

Closed
charleech opened this issue Aug 11, 2014 · 9 comments
Closed

Comments

@charleech
Copy link

Dear Sir,

The Bouncy Castle 1.51 removes the PGPSecretKey.extractPrivateKey(String), it cause the License3j some exception as

java.lang.NoSuchMethodError: org.bouncycastle.openpgp.PGPSecretKey.extractPrivateKey([CLjava/lang/String;)Lorg/bouncycastle/openpgp/PGPPrivateKey;
at com.verhas.licensor.License.encodeLicense(License.java:482)

By overview I've googled and found some example coding at [1]. If I'm not wrong it may be as the following: -

        PGPSecretKey                key          = null;
        String                      pin          = null;
        PGPDigestCalculatorProvider calcProvider = null;
        PBESecretKeyDecryptor       decryptor    = null;
        PGPPrivateKey               pKey         = null;
        try {
            key          = //Loading key
            pin          = "some-pin";
            calcProvider = new JcaPGPDigestCalculatorProviderBuilder().
                                    setProvider(BouncyCastleProvider.PROVIDER_NAME).
                                    build();
            decryptor    = new JcePBESecretKeyDecryptorBuilder(calcProvider).
                                    setProvider(BouncyCastleProvider.PROVIDER_NAME).
                                    build(pin.toCharArray());
            pKey         = key.extractPrivateKey(decryptor);

        } catch (PGPException e) {
            // TODO Handle the exception
            e.printStackTrace();
        } finally {
            key          = null;
            pin          = null;
            calcProvider = null;
            decryptor    = null;
            pKey         = null;
        }

Could you please help to consider? Thank you very much for your help in advance. I'm looking forward to hearing from you soon.

Regards,

Charlee Ch.

[1] https://github.com/bcgit/bc-java/blob/master/pg/src/test/java/org/bouncycastle/openpgp/test/PGPUnicodeTest.java

@verhas
Copy link
Owner

verhas commented Aug 11, 2014

I will have a look at this issue soon.

@verhas
Copy link
Owner

verhas commented Aug 17, 2014

The current HEAD contains the fix. I would appreciate if you could download, compile and have a look at it. I will release a new version in the coming weeks.

@charleech
Copy link
Author

Dear Sir,

I've build the HEAD as 1.0.6-SNAPSHOT with the -Dmaven.test.skip=true and tested against my three existing projects together with the Bouncy Castle 1.51 . Everything look great.

Anyhow I've found some trouble during testing the License3j as some test cases are failure at com.verhas.licensor.TestLicenseClass as the following [1].

I hope this information may be useful. If you have any question or need further information. Please do not hesitate to let me know.

Regards,

Charlee Ch.

[1] The surefire report

Tests run: 17, Failures: 3, Errors: 0, Skipped: 0, Time elapsed: 0.761 sec <<< FAILURE!
testMain(com.verhas.licensor.TestLicenseClass)  Time elapsed: 0.082 sec  <<< FAILURE!
junit.framework.ComparisonFailure: expected:<[a=b]
> but was:<[=b
]
>
    at junit.framework.Assert.assertEquals(Assert.java:85)
    at junit.framework.Assert.assertEquals(Assert.java:91)
    at com.verhas.licensor.TestLicenseClass.testMain(TestLicenseClass.java:302)
        ....

loadsEncodedLicenseString(com.verhas.licensor.TestLicenseClass)  Time elapsed: 0.008 sec  <<< FAILURE!
junit.framework.ComparisonFailure: expected:<[a=b]
> but was:<[=b
]
>
    at junit.framework.Assert.assertEquals(Assert.java:85)
    at junit.framework.Assert.assertEquals(Assert.java:91)
    at com.verhas.licensor.TestLicenseClass.loadsEncodedLicenseString(TestLicenseClass.java:141)
       ...

loadsEncodedLicenseFile(com.verhas.licensor.TestLicenseClass)  Time elapsed: 0.008 sec  <<< FAILURE!
junit.framework.ComparisonFailure: expected:<[a=b]
> but was:<[=b
]
>
    at junit.framework.Assert.assertEquals(Assert.java:85)
    at junit.framework.Assert.assertEquals(Assert.java:91)
    at com.verhas.licensor.TestLicenseClass.loadsEncodedLicenseFile(TestLicenseClass.java:157)
        ...

@verhas
Copy link
Owner

verhas commented Aug 18, 2014

That is a small bug in the test itself. Since you execute it on Windows the license text finishes a a=b\r\n On OSX, where I tested the code it is a=b\n. The test compared a=b\n to the last four characters to the string.

I will fix it some time.

@verhas
Copy link
Owner

verhas commented Aug 18, 2014

HEAD contains fix

@charleech
Copy link
Author

Dear Sir,

Sorry for late reply. I've test the HEAD against my Windows 7-64 bits environment. There are 2 test cases which is still failure as the following: -

-------------------------------------------------------------------------------
Test set: com.verhas.licensor.TestLicenseClass
-------------------------------------------------------------------------------
Tests run: 17, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 1.206 sec <<< FAILURE!

1.At the line 142

loadsEncodedLicenseString(com.verhas.licensor.TestLicenseClass)  Time elapsed: 0.011 sec  <<< FAILURE!
junit.framework.ComparisonFailure: expected:<[a=b]
> but was:<[=b
]
>
    at junit.framework.Assert.assertEquals(Assert.java:85)
    at junit.framework.Assert.assertEquals(Assert.java:91)
    at com.verhas.licensor.TestLicenseClass.loadsEncodedLicenseString(TestLicenseClass.java:142)

2.At the line 158

loadsEncodedLicenseFile(com.verhas.licensor.TestLicenseClass)  Time elapsed: 0.008 sec  <<< FAILURE!
junit.framework.ComparisonFailure: expected:<[a=b]
> but was:<[=b
]
>
    at junit.framework.Assert.assertEquals(Assert.java:85)
    at junit.framework.Assert.assertEquals(Assert.java:91)
    at com.verhas.licensor.TestLicenseClass.loadsEncodedLicenseFile(TestLicenseClass.java:158)

Anyhow I also have a chance to build against my CentOS environment. Everything look great. There is no any error. I hope this information may be useful.

I'm looking forward to seeing the new release soon.

Regards,

Charlee Ch.

@verhas
Copy link
Owner

verhas commented Aug 21, 2014

I modified the test so that it only checks that there is a stringa=b in the license and does not care that this is at the end of the string. It should be the case on any operating system no matter what line separator sequence is used in files.

charleech pushed a commit to charleech/License3j that referenced this issue Aug 22, 2014
Fix test case for windows by following the
verhas@bc23210
@charleech
Copy link
Author

Dear Sir,

I've try to fix the test case for windows as charleech@4d08b97.

Note: Please ignore the charleech@7d3b471

I found some trouble about the indent from my IDE and thought that it is not worth enough to create a pull request.

Could you please help to review? Thank you very much for your help in advance. I'm looking forward to hearing from you soon.

Regards,

Charlee Ch.

@verhas
Copy link
Owner

verhas commented May 20, 2015

Since this is an olc issue and the current version is using BC 1.52 I close this issue.

@verhas verhas closed this as completed May 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants