├── .classpath ├── .github └── workflows │ ├── ci-test.yml │ └── ci-test_provider.yml ├── .gitignore ├── .mvn ├── extensions.xml └── wrapper │ └── maven-wrapper.properties ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs └── org.eclipse.m2e.core.prefs ├── BUILDING.md ├── Gemfile ├── History.md ├── LICENSE.txt ├── Mavenfile ├── README.md ├── Rakefile ├── integration ├── 1.47 │ └── pom.xml ├── 1.48 │ └── pom.xml ├── 1.49 │ └── pom.xml ├── 1.50 │ └── pom.xml ├── Mavenfile └── pom.xml ├── jruby-openssl.gemspec ├── lib ├── jopenssl │ ├── load.rb │ └── version.rb ├── jruby-openssl.rb ├── openssl.rb └── openssl │ ├── bn.rb │ ├── buffering.rb │ ├── cipher.rb │ ├── config.rb │ ├── digest.rb │ ├── hmac.rb │ ├── marshal.rb │ ├── pkcs12.rb │ ├── pkcs5.rb │ ├── pkey.rb │ ├── ssl.rb │ └── x509.rb ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main └── java │ └── org │ └── jruby │ └── ext │ └── openssl │ ├── ASN1.java │ ├── BN.java │ ├── Cipher.java │ ├── CipherStrings.java │ ├── Digest.java │ ├── ExtConfig.java │ ├── HMAC.java │ ├── KDF.java │ ├── NetscapeSPKI.java │ ├── OCSP.java │ ├── OCSPBasicResponse.java │ ├── OCSPCertificateId.java │ ├── OCSPRequest.java │ ├── OCSPResponse.java │ ├── OCSPSingleResponse.java │ ├── OSSLLibrary.java │ ├── ObjectSupport.java │ ├── OpenSSL.java │ ├── PEMUtils.java │ ├── PKCS5.java │ ├── PKCS7.java │ ├── PKey.java │ ├── PKeyDH.java │ ├── PKeyDSA.java │ ├── PKeyEC.java │ ├── PKeyRSA.java │ ├── Random.java │ ├── SSL.java │ ├── SSLContext.java │ ├── SSLSession.java │ ├── SSLSocket.java │ ├── SecurityHelper.java │ ├── SimpleSecretKey.java │ ├── StringHelper.java │ ├── Utils.java │ ├── X509.java │ ├── X509Attribute.java │ ├── X509CRL.java │ ├── X509Cert.java │ ├── X509Extension.java │ ├── X509ExtensionFactory.java │ ├── X509Name.java │ ├── X509Request.java │ ├── X509Revoked.java │ ├── X509Store.java │ ├── X509StoreContext.java │ ├── impl │ ├── ASN1Registry.java │ ├── Attribute.java │ ├── BIO.java │ ├── BIOFilter.java │ ├── Base64.java │ ├── Base64BIOFilter.java │ ├── CipherBIOFilter.java │ ├── CipherSpec.java │ ├── Digest.java │ ├── ECPrivateKeyWithName.java │ ├── EVP.java │ ├── EncContent.java │ ├── Encrypt.java │ ├── Envelope.java │ ├── IssuerAndSerial.java │ ├── MemBIO.java │ ├── MessageDigestBIOFilter.java │ ├── Mime.java │ ├── MimeHeader.java │ ├── MimeParam.java │ ├── NetscapeCertRequest.java │ ├── NotVerifiedPKCS7Exception.java │ ├── NullSinkBIO.java │ ├── PKCS10Request.java │ ├── PKCS7.java │ ├── PKCS7Data.java │ ├── PKCS7DataData.java │ ├── PKCS7DataDigest.java │ ├── PKCS7DataEncrypted.java │ ├── PKCS7DataEnveloped.java │ ├── PKCS7DataSigned.java │ ├── PKCS7DataSignedAndEnveloped.java │ ├── PKCS7Exception.java │ ├── PKey.java │ ├── RecipInfo.java │ ├── SMIME.java │ ├── SignEnvelope.java │ ├── Signed.java │ ├── SignerInfoWithPkey.java │ ├── TypeDiscriminating.java │ └── pem │ │ ├── MiscPEMGeneratorHelper.java │ │ └── PEMUtilities.java │ ├── util │ ├── ByteArrayOutputStream.java │ └── Cache.java │ └── x509store │ ├── CRL.java │ ├── Certificate.java │ ├── CertificateFile.java │ ├── CertificateHashDir.java │ ├── Function0.java │ ├── Function1.java │ ├── Function2.java │ ├── Function3.java │ ├── Function4.java │ ├── Function5.java │ ├── Lookup.java │ ├── LookupMethod.java │ ├── Name.java │ ├── PEMInputOutput.java │ ├── PKey.java │ ├── PolicyTree.java │ ├── Purpose.java │ ├── Store.java │ ├── StoreContext.java │ ├── Trust.java │ ├── VerifyParameter.java │ ├── X509Aux.java │ ├── X509AuxCertificate.java │ ├── X509Error.java │ ├── X509Object.java │ └── X509Utils.java └── test ├── integration ├── Gemfile └── ssl_test.rb ├── java └── org │ └── jruby │ └── ext │ └── openssl │ ├── CipherSpiFake.java │ ├── CipherTest.java │ ├── SecurityHelperTest.java │ ├── SignatureSpiFake.java │ ├── VersionTest.java │ └── security │ └── SecurityManager.java ├── ossl └── ut_eof.rb └── ruby ├── dsa ├── private_key.pem └── test_dsa.rb ├── ec ├── base64.rb ├── ece.rb ├── hkdf.rb ├── private_key.pem ├── private_key2.pem ├── private_key_pkcs8.pem └── test_ec.rb ├── fixtures └── pkey │ ├── custom │ ├── ec256-private-v2.pem │ ├── ec256-public-v2.pem │ ├── ec256k-private.pem │ ├── ec256k-public.pem │ ├── ec512-private.pem │ ├── ec512-public.pem │ ├── rsa-2048-private.pem │ └── rsa-2048-public.pem │ ├── dsa1024 │ ├── dsa256 │ ├── dsa512 │ ├── p256 │ ├── rsa1024 │ └── rsa2048 ├── oaep ├── encrypted.key └── test_oaep.rb ├── pkcs5 └── test_pbkdf2.rb ├── pkcs7 ├── pkcs7_mime_enveloped.message ├── pkcs7_mime_signed.message ├── pkcs7_multipart_signed.message ├── test_attribute.rb ├── test_bio.rb ├── test_mime.rb ├── test_pkcs7.rb └── test_smime.rb ├── pkcs7_helper.rb ├── pkey-cert.pem ├── pkey-pkcs8.pem ├── rsa ├── private_key.pem ├── private_key_with_pass.pem ├── public_key.pub └── test_rsa.rb ├── ssl ├── client.crt ├── client.key ├── letsencrypt │ ├── isrg-root-x1-cross-signed.pem │ ├── isrgrootx1.pem │ ├── lets-encrypt-r3-cross-signed.pem │ └── lets-encrypt-r3.pem ├── server.crt ├── server.key ├── ssl_server.rb ├── test_context.rb ├── test_helper.rb ├── test_ocsp.rb ├── test_session.rb ├── test_socket.rb └── test_ssl.rb ├── test_asn1.rb ├── test_bn.rb ├── test_cipher.rb ├── test_digest.rb ├── test_helper.rb ├── test_hmac.rb ├── test_openssl.rb ├── test_pkey.rb ├── test_random.rb ├── test_security.rb ├── test_security_helper.rb └── x509 ├── Entrust.net_Premium_2048_Secure_Server_CA.pem ├── Entrust.net_Secure_Server_CA.expired.pem ├── SETUP.txt ├── ca.crt ├── demoCA ├── cacert.pem ├── careq.pem ├── index.txt ├── index.txt.attr ├── index.txt.attr.old ├── index.txt.old ├── newcerts │ ├── 7FE0E82756779BDA39DFF3AEE16916DE984FFD24.pem │ └── 7FE0E82756779BDA39DFF3AEE16916DE984FFD25.pem ├── private │ ├── cakey.pem │ └── cakey.pem.passwd ├── serial └── serial.old ├── digicert.pem ├── dsa.crt ├── ec-ca.crl ├── ec-ca.crt ├── ec.crt ├── gibberish.pem ├── javastore.ts ├── newcert.pem ├── newkey.pem ├── newreq.pem ├── revoked.crl ├── rsa.crt ├── test_x509cert.rb ├── test_x509crl.rb ├── test_x509ext.rb ├── test_x509name.rb ├── test_x509req.rb ├── test_x509revoked.rb └── test_x509store.rb /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /.github/workflows/ci-test.yml: -------------------------------------------------------------------------------- 1 | name: rake test 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | JAVA_OPTS: '-XX:+TieredCompilation -XX:TieredStopAtLevel=1' 7 | JRUBY_OPTS: '-J-ea' 8 | 9 | jobs: 10 | 11 | maven-test: 12 | runs-on: ubuntu-22.04 13 | 14 | strategy: 15 | matrix: 16 | ruby-version: [ jruby-9.4.12.0 ] 17 | java-version: [ 8, 11, 21, 23 ] 18 | distribution: [ temurin ] 19 | include: 20 | - java-version: 8 21 | distribution: temurin 22 | ruby-version: jruby-9.2.19.0 23 | - java-version: 11 24 | distribution: temurin 25 | ruby-version: jruby-9.2.20.1 26 | - java-version: 8 27 | distribution: temurin 28 | ruby-version: jruby-9.3.3.0 29 | - java-version: 11 30 | distribution: temurin 31 | ruby-version: jruby-9.3.13.0 32 | - java-version: 21 33 | distribution: oracle 34 | ruby-version: jruby-9.3.13.0 35 | - java-version: 11 36 | distribution: zulu 37 | ruby-version: jruby-9.4.5.0 38 | - java-version: 17 39 | distribution: oracle 40 | ruby-version: jruby-9.4.7.0 41 | - java-version: 21 42 | distribution: oracle 43 | ruby-version: jruby-9.4.8.0 44 | - java-version: 21 45 | distribution: zulu 46 | ruby-version: jruby-head # 10.0 47 | - java-version: 24 48 | distribution: corretto 49 | ruby-version: jruby-head # 10.0 50 | fail-fast: false 51 | 52 | steps: 53 | - name: checkout 54 | uses: actions/checkout@v2 55 | 56 | - name: set up java ${{ matrix.java-version }} 57 | uses: actions/setup-java@v4 58 | with: 59 | java-version: ${{ matrix.java-version }} 60 | distribution: ${{ matrix.distribution }} 61 | 62 | - name: set up ${{ matrix.ruby-version }} 63 | uses: ruby/setup-ruby@v1 64 | with: 65 | ruby-version: ${{ matrix.ruby-version }} 66 | 67 | - name: install bundler 68 | run: jruby -S gem install bundler -v "~>2.2.28" 69 | 70 | - name: bundle install 71 | run: jruby -S bundle install 72 | 73 | - name: rake test_prepare 74 | run: jruby -rbundler/setup -S rake test_prepare 75 | 76 | - name: rake test 77 | run: jruby -rbundler/setup -S rake test 78 | -------------------------------------------------------------------------------- /.github/workflows/ci-test_provider.yml: -------------------------------------------------------------------------------- 1 | name: rake test (with provider) 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | JAVA_OPTS: '-Djruby.openssl.provider.register=true -Djruby.openssl.warn=true ' 7 | JRUBY_OPTS: '-J-ea -J--add-opens=java.base/java.security=org.jruby.dist -Xjit.threshold=0' 8 | 9 | jobs: 10 | 11 | maven-test: 12 | runs-on: ubuntu-24.04 # ubuntu-latest 13 | 14 | strategy: 15 | matrix: 16 | ruby-version: [ jruby-9.4.12.0 ] 17 | java-version: [ 21, 23 ] 18 | distribution: [ temurin, oracle ] 19 | include: 20 | - ruby-version: jruby-9.4.8.0 21 | java-version: 11 22 | distribution: corretto 23 | - ruby-version: jruby-9.4.8.0 24 | java-version: 11 25 | distribution: zulu 26 | - ruby-version: jruby-9.4.8.0 27 | java-version: 11 28 | distribution: temurin 29 | fail-fast: false 30 | 31 | steps: 32 | - name: checkout 33 | uses: actions/checkout@v2 34 | 35 | - name: set up java ${{ matrix.java-version }} 36 | uses: actions/setup-java@v4 37 | with: 38 | java-version: ${{ matrix.java-version }} 39 | distribution: ${{ matrix.distribution }} 40 | 41 | - name: set up ${{ matrix.ruby-version }} 42 | uses: ruby/setup-ruby@v1 43 | with: 44 | ruby-version: ${{ matrix.ruby-version }} 45 | 46 | - name: install bundler 47 | run: jruby -S gem install bundler -v "~>2.2.28" 48 | 49 | - name: bundle install 50 | run: jruby -S bundle install 51 | 52 | - name: rake test_prepare 53 | run: jruby -rbundler/setup -S rake test_prepare 54 | 55 | - name: rake test 56 | run: jruby -rbundler/setup -S rake test 57 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gemspec.xml 2 | pkg 3 | *.jar 4 | target 5 | build.log 6 | .idea 7 | *.iml 8 | *.lock 9 | lib/org 10 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | org.jruby.maven 5 | mavengem-wagon 6 | 2.0.2 7 | 8 | 9 | io.takari.polyglot 10 | polyglot-ruby 11 | 0.7.0 12 | 13 | 14 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.8/apache-maven-3.8.8-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar 19 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=utf-8 3 | encoding/=utf-8 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.6 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /BUILDING.md: -------------------------------------------------------------------------------- 1 | ## JRuby-OpenSSL 2 | 3 | The project is using [Maven](http://maven.apache.org/download.cgi) for build. 4 | 5 | Maven enhanced with JRuby using [Polyglot](https://github.com/takari/polyglot-maven), 6 | allows the build to be written using a Ruby DSL - check [*Mavenfile*](Mavenfile). 7 | 8 | If you're coming from a Ruby world and do not have Maven setup, you can alternatively 9 | `jruby -S gem install ruby-maven` and use the `rmvn` executable (instead of `mvn`). 10 | 11 | ### Building 12 | 13 | The usual `./mvnw package -Dmaven.test.skip=true` builds a .gem that includes the JRuby extension .jar 14 | 15 | There's a rake target as well that shells out: `jruby -S rake jar` 16 | 17 | ### Testing 18 | 19 | NOTE: the ext .jar needs to be build (see the Building section above on `rake jar`) 20 | 21 | The full unit test suite can be boostraped using Rake: `jruby -S rake test` 22 | 23 | Tests can also be run individually e.g. `jruby -Ilib:src/test/ruby src/test/ruby/test_bn.rb` 24 | 25 | NOTE: make sure to **-Ilib** otherwise you end up using the OpenSSL default gem shipped with JRuby. 26 | 27 | ### Releasing 28 | 29 | * fill in [History.md](History.md) change-log entries for release 30 | 31 | * update `VERSION` at [lib/jopenssl/version.rb](lib/jopenssl/version.rb), 32 | make sure [pom.xml](pom.xml) is regenerated e.g. using `rmvn validate` 33 | and `git commit` the changes 34 | 35 | * `./mvnw -Prelease -DupdateReleaseInfo=true -Dmaven.test.skip=true clean package` 36 | 37 | * gem push the build gem from pkg/ e.g. `gem push pkg/jruby-openssl-0.9.15.gem` 38 | 39 | * tag the release e.g. `git tag v0.9.15` 40 | 41 | * update `VERSION` to next SNAPSHOT (e.g. `"0.9.16.dev"`) and commit 42 | make sure [pom.xml](pom.xml) is regenerated (`./mvnw validate`) 43 | 44 | * `git push origin master --tags` 45 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in the gemspec 4 | gemspec if defined? JRUBY_VERSION 5 | 6 | gem "rake", require: false 7 | gem 'mocha', '~> 1.4', '< 2.0' 8 | 9 | # NOTE: runit-maven-plugin will use it's own : 10 | gem 'test-unit' 11 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | JRuby-OpenSSL is distributed under the same license as JRuby a tri EPL/GPL/LGPL 2 | license. You can use it, redistribute it and/or modify it under the terms of the: 3 | 4 | Eclipse Public License version 1.0 5 | GNU General Public License version 2.0 6 | GNU Lesser General Public License version 2.1 7 | 8 | The contents of this file are subject to the Common Public License Version 1.0 9 | (the "License"); you may not use this file except in compliance with the License. 10 | You may obtain a copy of the License at http://www.eclipse.org/legal/cpl-v10.html 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 14 | FOR APARTICULAR PURPOSE AND NONINFRINGEMENT. 15 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 16 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 17 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | DEALINGS IN THE SOFTWARE. 19 | 20 | Copyright (C) 2007-2009 Ola Bini 21 | Copyright (C) 2009-2024 The JRuby Team 22 | 23 | Alternatively, the contents of this file may be used under the terms of 24 | either of the GNU General Public License Version 2 or later (the "GPL"), 25 | or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 26 | in which case the provisions of the GPL or the LGPL are applicable instead 27 | of those above. If you wish to allow use of your version of this file only 28 | under the terms of either the GPL or the LGPL, and not to allow others to 29 | use your version of this file under the terms of the EPL, indicate your 30 | decision by deleting the provisions above and replace them with the notice 31 | and other provisions required by the GPL or the LGPL. If you do not delete 32 | the provisions above, a recipient may use your version of this file under 33 | the terms of any one of the EPL, the GPL or the LGPL. 34 | 35 | 36 | JRuby-OpenSSL includes software by The Legion of the Bouncy Castle Inc. 37 | Please, visit (http://bouncycastle.org/license.html) for licensing details. 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JRuby-OpenSSL 2 | 3 | [JRuby-OpenSSL](https://github.com/jruby/jruby-openssl) is an add-on gem for 4 | [JRuby](https://www.jruby.org/) that emulates the Ruby OpenSSL native library. 5 | 6 | Under the hood uses the [Bouncy Castle Crypto APIs](https://www.bouncycastle.org/java.html). 7 | 8 | Each jruby-openssl gem release includes a certain version, usually the latest available, 9 | of the library (namely BC Provider and PKIX/CMS/EAC/PKCS/OCSP/TSP/OPENSSL jars). 10 | 11 | Please report bugs and incompatibilities (preferably with test-cases) to either 12 | the JRuby [mailing list][1] or the [bug tracker][2]. 13 | 14 | ## Compatibility 15 | 16 | | JRuby-OpenSSL | JRuby compat | JVM compat | supported BC | 17 | |---------------|:------------:|-----------:|-------------:| 18 | | 0.9.6 | 1.6.8-9.0.2 | Java 6-8 | 1.47-1.50 | 19 | | 0.9.12 | 1.6.8-9.0.5 | Java 6-8 | 1.47-1.52 | 20 | | 0.9.13 | 1.6.8-9.1.2 | Java 6-8 | 1.49-1.52 | 21 | | 0.9.14 | 1.6.8-9.1.5 | Java 6-8 | 1.49-1.54 | 22 | | 0.9.17 | 1.6.8-9.1.5 | Java 6-8 | 1.50-1.54 | 23 | | ~>0.9.18 | 1.6.8-9.1.x | Java 6-8 | 1.50-1.55 | 24 | | 0.10.0 | 1.7.20-9.2.x | Java 7-10 | 1.55-1.59 | 25 | | 0.10.3 | 1.7.20-9.2.x | Java 7-11 | 1.56-1.62 | 26 | | ~>0.10.5 | 1.7.20-9.3.x | Java 7-11 | 1.60-1.68 | 27 | | ~>0.11.x | 9.0.x-9.3.x | Java 7-11 | 1.62-1.68 | 28 | | ~>0.12.x | 9.1.x-9.3.x | Java 8-15 | 1.65-1.68 | 29 | | ~>0.13.x | 9.1.x-9.4.x | Java 8-17 | 1.68-1.69 | 30 | | ~>0.14.x | 9.1.x-9.4.x | Java 8-21 | 1.71-1.74 | 31 | | ~>0.15.x | 9.2.x-9.4.x | Java 8-21 | 1.76-1.79 | 32 | 33 | NOTE: backwards JRuby compatibility was not handled for versions <= **0.9.6** 34 | 35 | ## Security 36 | 37 | JRuby-OpenSSL is an essential part of [JRuby](https://www.jruby.org/), please report security vulnerabilities to 38 | `security@jruby.org` as detailed on JRuby's [security page](https://www.jruby.org/security) or using [GitHub][0]. 39 | 40 | Please note that most OpenSSL vulnerabilities do not effect JRuby since its not using 41 | any of OpenSSL's C code, only Ruby parts (*.rb) are the same as in MRI's OpenSSL library. 42 | 43 | ## Testing 44 | 45 | [![Build Status][0]](http://travis-ci.org/jruby/jruby-openssl) 46 | 47 | rake jar:all # creates pom.xml and generates jopenssl.jar under lib 48 | mvn test 49 | 50 | will run (junit as well as ruby) tests and a some ruby tests against the default 51 | jruby version. to pick a different JRuby version run 52 | 53 | mvn test -Djruby.versions=9.2.8.0 54 | 55 | for running integration-tests the gem will be first installed and then the same 56 | tests run for each possible bouncy-castle version (see [listing][3]), run with 57 | 58 | mvn verify -P test-9.2.9.0,test-9.1.17.0 59 | 60 | or pick a bouncy-castle version 61 | 62 | mvn verify -P test-9.2.9.0 -Dbc.versions=1.60 63 | 64 | NOTE: you can pick any jruby version which is on [central][4] or on [ci.jruby][5] 65 | 66 | ## License 67 | 68 | (c) 2009-2024 JRuby distributed under EPL 1.0/GPL 2.0/LGPL 2.1 69 | 70 | [0]: https://github.com/jruby/jruby-openssl/security 71 | [1]: https://github.com/jruby/jruby/wiki/MailingLists 72 | [2]: https://github.com/jruby/jruby-openssl/issues/new 73 | [3]: https://github.com/jruby/jruby-openssl/tree/master/integration 74 | [4]: http://central.maven.org/maven2/org/jruby/ 75 | [5]: https://www.jruby.org/nightly 76 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #-*- mode: ruby -*- 2 | 3 | #Rake::Task[:jar].clear rescue nil 4 | desc "Package jopenssl.jar with the compiled classes" 5 | task :jar do 6 | sh( './mvnw prepare-package -Dmaven.test.skip=true' ) 7 | end 8 | namespace :jar do 9 | desc "Package jopenssl.jar file (and dependendent jars)" 10 | task :all do 11 | sh( './mvnw package -Dmaven.test.skip=true' ) 12 | end 13 | end 14 | task :test_prepare do 15 | sh( './mvnw prepare-package -Dmaven.test.skip=true' ) 16 | sh( './mvnw test-compile' ) # separate step due -Dmaven.test.skip=true 17 | end 18 | 19 | task :clean do 20 | sh( './mvnw clean' ) 21 | end 22 | 23 | task :build do 24 | sh( './mvnw clean package -Dmaven.test.skip=true' ) 25 | end 26 | 27 | task :default => :build 28 | 29 | file('lib/jopenssl.jar') { Rake::Task['jar'].invoke } 30 | 31 | require 'rake/testtask' 32 | Rake::TestTask.new do |task| 33 | task.libs << File.expand_path('src/test/ruby', File.dirname(__FILE__)) 34 | test_files = FileList['src/test/ruby/**/test*.rb'].to_a 35 | task.test_files = test_files.map { |path| path.sub('src/test/ruby/', '') } 36 | task.verbose = true 37 | task.loader = :direct 38 | task.ruby_opts = [ '-C', 'src/test/ruby', '-rbundler/setup' ] 39 | end 40 | task :test => 'lib/jopenssl.jar' 41 | 42 | namespace :integration do 43 | it_path = File.expand_path('../src/test/integration', __FILE__) 44 | task :install do 45 | ruby "-C #{it_path} -S bundle install" 46 | end 47 | # desc "Run IT tests" 48 | task :test => 'lib/jopenssl.jar' do 49 | unless File.exist?(File.join(it_path, 'Gemfile.lock')) 50 | raise "bundle not installed, run `rake integration:install'" 51 | end 52 | loader = "ARGV.each { |f| require f }" 53 | lib = [ File.expand_path('../lib', __FILE__), it_path ] 54 | test_files = FileList['src/test/integration/*_test.rb'].map { |path| path.sub('src/test/integration/', '') } 55 | ruby "-I#{lib.join(':')} -C src/test/integration -e \"#{loader}\" #{test_files.map { |f| "\"#{f}\"" }.join(' ')}" 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /integration/1.47/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | none 7 | base 8 | 0 9 | 10 | bouncy-castle 11 | 1.47 12 | 13 | ${project.version} 14 | 15 | 16 | -------------------------------------------------------------------------------- /integration/1.48/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | none 7 | base 8 | 0 9 | 10 | bouncy-castle 11 | 1.48 12 | 13 | ${project.version} 14 | 15 | 16 | -------------------------------------------------------------------------------- /integration/1.49/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | none 7 | base 8 | 0 9 | 10 | bouncy-castle 11 | 1.49 12 | 13 | ${project.version} 14 | 15 | 16 | -------------------------------------------------------------------------------- /integration/1.50/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | none 7 | base 8 | 0 9 | 10 | bouncy-castle 11 | 1.50 12 | 13 | ${project.version} 14 | 15 | 16 | -------------------------------------------------------------------------------- /integration/Mavenfile: -------------------------------------------------------------------------------- 1 | #-*- mode: ruby -*- 2 | 3 | id 'none:base:0' 4 | packaging :pom 5 | 6 | snapshot_repository :id => 'jruby', :url => 'http://ci.jruby.org/snapshots/maven' 7 | 8 | # TODO should be setup whenever a plugin uses gems 9 | plugin_repository :id => 'rubygems-releases', :url => 'http://rubygems-proxy.torquebox.org/releases' 10 | 11 | base_path = File.expand_path('..', File.dirname(__FILE__)) 12 | bc_version = File.read("#{base_path}/lib/jopenssl/version.rb")[/BOUNCY_CASTLE_VERSION\s?=\s?'(.*?)'/, 1] 13 | 14 | properties( 'bc.version' => bc_version, # to satisfy maven 15 | 'jruby.openssl.version' => '0.9.7', # to satisfy maven 16 | # use the gem-maven-plugin repo for the tests 17 | 'gem.home' => '${basedir}/../pkg/rubygems', 18 | 'gem.path' => '${basedir}/../pkg/rubygems', 19 | 'tesla.dump.pom' => 'pom.xml', 20 | 'tesla.dump.readonly' => true, 21 | 'jruby.version' => '1.7.19', # for jruby-maven-plugins 22 | 'jruby.plugins.version' => '1.0.9' ) 23 | 24 | jruby_plugin :gem, :gemHomes => { 'gem-maven-plugin' => '${gem.home}' } do 25 | execute_goal :initialize 26 | 27 | gem 'jar-dependencies', '0.1.8' # TODO change after 0.1.15 is out 28 | spec = Gem::Specification.load "#{base_path}/jruby-openssl.gemspec" 29 | spec.development_dependencies.each do |dev_spec| 30 | gem dev_spec.name, *dev_spec.requirements_list 31 | end 32 | 33 | # make sure we have those in the local repo 34 | # BUT not be part of the runit-classloader 35 | # otherwise jruby-1.7.x and jruby-1.6.x will not use those 36 | # required in the test_*.rb files 37 | jar 'org.bouncycastle', 'bcpkix-jdk15on', '${bc.version}' 38 | jar 'org.bouncycastle', 'bcprov-jdk15on', '${bc.version}' 39 | #spec.requirements.each do |req| 40 | # req = req.sub('jar', '').split(',').each(&:strip!) 41 | # jar req[0], req[1] 42 | #end 43 | 44 | gem 'jruby-openssl', '${jruby.openssl.version}' 45 | 46 | end 47 | 48 | jruby_plugin :runit do 49 | execute_goal( :test, 50 | :env => { 'BC_VERSION' => '${bc.version}' }, 51 | :jrubySwitches => '-I../../lib', 52 | :runitDirectory => '../../src/test/ruby/**/test_*.rb', 53 | :versions => '${jruby.versions}', 54 | :modes => '${jruby.modes}' ) 55 | end 56 | 57 | # vim: syntax=Ruby 58 | -------------------------------------------------------------------------------- /jruby-openssl.gemspec: -------------------------------------------------------------------------------- 1 | #-*- mode: ruby -*- 2 | 3 | Gem::Specification.new do |s| 4 | s.name = 'jruby-openssl' 5 | 6 | version_rb = File.expand_path('lib/jopenssl/version.rb', File.dirname(__FILE__)) 7 | version_rb = File.read(version_rb) 8 | s.version = version_rb.match( /.*\sVERSION\s*=\s*['"](.*)['"]/ )[1] 9 | 10 | s.platform = 'java' 11 | s.authors = ['Karol Bucek', 'Ola Bini', 'JRuby contributors'] 12 | s.email = 'self+jruby-openssl@kares.org' 13 | s.summary = "JRuby OpenSSL" 14 | s.homepage = 'https://github.com/jruby/jruby-openssl' 15 | s.description = 'JRuby-OpenSSL is an add-on gem for JRuby that emulates the Ruby OpenSSL native library.' 16 | s.licenses = [ 'EPL-1.0', 'GPL-2.0', 'LGPL-2.1' ] 17 | 18 | s.require_paths = ['lib'] 19 | 20 | s.files = `git ls-files`.split("\n"). 21 | select { |f| f =~ /^(lib)/ || 22 | f =~ /^(History|LICENSE|README|Rakefile|Mavenfile|pom.xml)/i } + 23 | Dir.glob('lib/**/*.jar') # 'lib/jopenssl.jar' and potentially BC jars 24 | 25 | bc_version = version_rb.match( /.*\sBOUNCY_CASTLE_VERSION\s*=\s*['"](.*)['"]/ )[1] 26 | raise 'BOUNCY_CASTLE_VERSION not matched' if (bc_version || '').empty? 27 | 28 | s.required_ruby_version = '>= 2.5.0' # JRuby >= 9.2 29 | 30 | s.requirements << "jar org.bouncycastle:bcprov-jdk18on, #{bc_version}" # Provider 31 | s.requirements << "jar org.bouncycastle:bcpkix-jdk18on, #{bc_version}" # PKIX/CMS/EAC/PKCSOCSP/TSP/OPENSSL 32 | s.requirements << "jar org.bouncycastle:bctls-jdk18on, #{bc_version}" # DTLS/TLS API/JSSE Provider 33 | s.requirements << "jar org.bouncycastle:bcutil-jdk18on, #{bc_version}" 34 | 35 | end 36 | 37 | # vim: syntax=Ruby 38 | -------------------------------------------------------------------------------- /lib/jopenssl/load.rb: -------------------------------------------------------------------------------- 1 | require 'jopenssl/version' 2 | 3 | # NOTE: assuming user does pull in BC .jars from somewhere else on the CP 4 | unless ENV_JAVA['jruby.openssl.load.jars'].eql?('false') 5 | version = JOpenSSL::BOUNCY_CASTLE_VERSION 6 | begin 7 | require 'jar-dependencies' 8 | # if we have jar-dependencies we let it track the jars 9 | require_jar 'org.bouncycastle', 'bcprov-jdk18on', version 10 | require_jar 'org.bouncycastle', 'bcpkix-jdk18on', version 11 | require_jar 'org.bouncycastle', 'bcutil-jdk18on', version 12 | require_jar 'org.bouncycastle', 'bctls-jdk18on', version 13 | bc_jars = true 14 | rescue LoadError, RuntimeError 15 | bc_jars = false 16 | end 17 | unless bc_jars 18 | load "org/bouncycastle/bcprov-jdk18on/#{version}/bcprov-jdk18on-#{version}.jar" 19 | load "org/bouncycastle/bcpkix-jdk18on/#{version}/bcpkix-jdk18on-#{version}.jar" 20 | load "org/bouncycastle/bcutil-jdk18on/#{version}/bcutil-jdk18on-#{version}.jar" 21 | load "org/bouncycastle/bctls-jdk18on/#{version}/bctls-jdk18on-#{version}.jar" 22 | end 23 | end 24 | 25 | require 'jopenssl.jar' 26 | JRuby::Util.load_ext('org.jruby.ext.openssl.OpenSSL') 27 | 28 | # NOTE: content bellow should live in *lib/openssl.rb* but due RubyGems/Bundler 29 | # `autoload :OpenSSL` this will cause issues if an older version (0.11) is the 30 | # default gem under JRuby 9.2 (which on auto-load does not trigger a dynamic 31 | # require - this is only fixed in JRuby 9.3) 32 | 33 | module OpenSSL 34 | autoload :Config, 'openssl/config' unless const_defined?(:Config, false) 35 | autoload :ConfigError, 'openssl/config' unless const_defined?(:ConfigError, false) 36 | autoload :PKCS12, 'openssl/pkcs12' 37 | end 38 | 39 | =begin 40 | = Info 41 | 'OpenSSL for Ruby 2' project 42 | Copyright (C) 2002 Michal Rokos 43 | All rights reserved. 44 | 45 | = Licence 46 | This program is licensed under the same licence as Ruby. 47 | (See the file 'LICENCE'.) 48 | =end 49 | 50 | require 'openssl/bn' 51 | require 'openssl/pkey' 52 | require 'openssl/cipher' 53 | require 'openssl/digest' 54 | require 'openssl/hmac' 55 | require 'openssl/x509' 56 | require 'openssl/ssl' 57 | require 'openssl/pkcs5' 58 | 59 | module OpenSSL 60 | # call-seq: 61 | # OpenSSL.secure_compare(string, string) -> boolean 62 | # 63 | # Constant time memory comparison. Inputs are hashed using SHA-256 to mask 64 | # the length of the secret. Returns +true+ if the strings are identical, 65 | # +false+ otherwise. 66 | def self.secure_compare(a, b) 67 | hashed_a = OpenSSL::Digest.digest('SHA256', a) 68 | hashed_b = OpenSSL::Digest.digest('SHA256', b) 69 | OpenSSL.fixed_length_secure_compare(hashed_a, hashed_b) && a == b 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /lib/jopenssl/version.rb: -------------------------------------------------------------------------------- 1 | module JOpenSSL 2 | VERSION = '0.15.5.dev' 3 | BOUNCY_CASTLE_VERSION = '1.80' 4 | end 5 | 6 | Object.class_eval do 7 | Jopenssl = JOpenSSL 8 | private_constant :Jopenssl if respond_to?(:private_constant) 9 | deprecate_constant :Jopenssl if respond_to?(:deprecate_constant) 10 | end 11 | -------------------------------------------------------------------------------- /lib/jruby-openssl.rb: -------------------------------------------------------------------------------- 1 | # This file allows older version of JRuby (prior to 1.7.5) to explicitly load 2 | # the gem version of jruby-openssl rather than the stdlib version. JRuby 1.7.5 3 | # and higher use the "default gems" capability of RubyGems. 4 | 5 | require 'jopenssl/load' -------------------------------------------------------------------------------- /lib/openssl.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'jopenssl/load' 4 | -------------------------------------------------------------------------------- /lib/openssl/bn.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | #-- 3 | # 4 | # = Ruby-space definitions that completes C-space funcs for BN 5 | # 6 | # = Info 7 | # 'OpenSSL for Ruby 2' project 8 | # Copyright (C) 2002 Michal Rokos 9 | # All rights reserved. 10 | # 11 | # = Licence 12 | # This program is licensed under the same licence as Ruby. 13 | # (See the file 'LICENCE'.) 14 | #++ 15 | 16 | module OpenSSL 17 | class BN 18 | include Comparable 19 | 20 | def pretty_print(q) 21 | q.object_group(self) { 22 | q.text ' ' 23 | q.text to_i.to_s 24 | } 25 | end 26 | end # BN 27 | end # OpenSSL 28 | 29 | ## 30 | #-- 31 | # Add double dispatch to Integer 32 | #++ 33 | class Integer 34 | # Casts an Integer as an OpenSSL::BN 35 | # 36 | # See `man bn` for more info. 37 | def to_bn 38 | OpenSSL::BN::new(self) 39 | end 40 | end # Integer 41 | -------------------------------------------------------------------------------- /lib/openssl/cipher.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | #-- 3 | # = Ruby-space predefined Cipher subclasses 4 | # 5 | # = Info 6 | # 'OpenSSL for Ruby 2' project 7 | # Copyright (C) 2002 Michal Rokos 8 | # All rights reserved. 9 | # 10 | # = Licence 11 | # This program is licensed under the same licence as Ruby. 12 | # (See the file 'LICENCE'.) 13 | #++ 14 | 15 | module OpenSSL 16 | class Cipher 17 | # %w(AES CAST5 BF DES IDEA RC2 RC4 RC5).each{|name| 18 | # klass = Class.new(Cipher){ 19 | # define_method(:initialize){|*args| 20 | # cipher_name = args.inject(name){|n, arg| "#{n}-#{arg}" } 21 | # super(cipher_name.downcase) 22 | # } 23 | # } 24 | # const_set(name, klass) 25 | # } 26 | # 27 | # %w(128 192 256).each{|keylen| 28 | # klass = Class.new(Cipher){ 29 | # define_method(:initialize){|mode = "CBC"| 30 | # super("aes-#{keylen}-#{mode}".downcase) 31 | # } 32 | # } 33 | # const_set("AES#{keylen}", klass) 34 | # } 35 | 36 | # call-seq: 37 | # cipher.random_key -> key 38 | # 39 | # Generate a random key with OpenSSL::Random.random_bytes and sets it to 40 | # the cipher, and returns it. 41 | # 42 | # You must call #encrypt or #decrypt before calling this method. 43 | # def random_key 44 | # str = OpenSSL::Random.random_bytes(self.key_len) 45 | # self.key = str 46 | # end 47 | 48 | # call-seq: 49 | # cipher.random_iv -> iv 50 | # 51 | # Generate a random IV with OpenSSL::Random.random_bytes and sets it to the 52 | # cipher, and returns it. 53 | # 54 | # You must call #encrypt or #decrypt before calling this method. 55 | # def random_iv 56 | # str = OpenSSL::Random.random_bytes(self.iv_len) 57 | # self.iv = str 58 | # end 59 | 60 | # Deprecated. 61 | # 62 | # This class is only provided for backwards compatibility. 63 | # Use OpenSSL::Cipher. 64 | class Cipher < Cipher; end 65 | deprecate_constant :Cipher 66 | end # Cipher 67 | end # OpenSSL 68 | -------------------------------------------------------------------------------- /lib/openssl/digest.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | #-- 3 | # = Ruby-space predefined Digest subclasses 4 | # 5 | # = Info 6 | # 'OpenSSL for Ruby 2' project 7 | # Copyright (C) 2002 Michal Rokos 8 | # All rights reserved. 9 | # 10 | # = Licence 11 | # This program is licensed under the same licence as Ruby. 12 | # (See the file 'LICENCE'.) 13 | #++ 14 | 15 | module OpenSSL 16 | class Digest 17 | 18 | # Return the hash value computed with _name_ Digest. _name_ is either the 19 | # long name or short name of a supported digest algorithm. 20 | # 21 | # === Examples 22 | # 23 | # OpenSSL::Digest.digest("SHA256", "abc") 24 | # 25 | # which is equivalent to: 26 | # 27 | # OpenSSL::Digest.digest('SHA256', "abc") 28 | # 29 | # def self.digest(name, data) 30 | # super(data, name) 31 | # end 32 | # 33 | # %w(MD4 MD5 RIPEMD160 SHA1 SHA224 SHA256 SHA384 SHA512).each do |name| 34 | # klass = Class.new(self) { 35 | # define_method(:initialize, ->(data = nil) {super(name, data)}) 36 | # } 37 | # 38 | # singleton = (class << klass; self; end) 39 | # 40 | # singleton.class_eval{ 41 | # define_method(:digest) {|data| new.digest(data)} 42 | # define_method(:hexdigest) {|data| new.hexdigest(data)} 43 | # } 44 | # 45 | # const_set(name.tr('-', '_'), klass) 46 | # end 47 | 48 | # Deprecated. 49 | # 50 | # This class is only provided for backwards compatibility. 51 | # Use OpenSSL::Digest instead. 52 | class Digest < Digest; end # :nodoc: 53 | deprecate_constant :Digest 54 | 55 | end # Digest 56 | 57 | # Returns a Digest subclass by _name_ 58 | # 59 | # require 'openssl' 60 | # 61 | # OpenSSL::Digest("MD5") 62 | # # => OpenSSL::Digest::MD5 63 | # 64 | # Digest("Foo") 65 | # # => NameError: wrong constant name Foo 66 | 67 | def Digest(name) 68 | OpenSSL::Digest.const_get(name) 69 | end 70 | 71 | module_function :Digest 72 | 73 | end # OpenSSL 74 | -------------------------------------------------------------------------------- /lib/openssl/hmac.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module OpenSSL 4 | class HMAC 5 | # Securely compare with another HMAC instance in constant time. 6 | def ==(other) 7 | return false unless HMAC === other 8 | return false unless self.digest.bytesize == other.digest.bytesize 9 | 10 | OpenSSL.fixed_length_secure_compare(self.digest, other.digest) 11 | end 12 | 13 | # :call-seq: 14 | # hmac.base64digest -> string 15 | # 16 | # Returns the authentication code an a Base64-encoded string. 17 | def base64digest 18 | [digest].pack("m0") 19 | end 20 | 21 | class << self 22 | # :call-seq: 23 | # HMAC.digest(digest, key, data) -> aString 24 | # 25 | # Returns the authentication code as a binary string. The _digest_ parameter 26 | # specifies the digest algorithm to use. This may be a String representing 27 | # the algorithm name or an instance of OpenSSL::Digest. 28 | # 29 | # === Example 30 | # key = 'key' 31 | # data = 'The quick brown fox jumps over the lazy dog' 32 | # 33 | # hmac = OpenSSL::HMAC.digest('SHA1', key, data) 34 | # #=> "\xDE|\x9B\x85\xB8\xB7\x8A\xA6\xBC\x8Az6\xF7\n\x90p\x1C\x9D\xB4\xD9" 35 | def digest(digest, key, data) 36 | hmac = new(key, digest) 37 | hmac << data 38 | hmac.digest 39 | end unless method_defined?(:digest) # JRuby 40 | 41 | # :call-seq: 42 | # HMAC.hexdigest(digest, key, data) -> aString 43 | # 44 | # Returns the authentication code as a hex-encoded string. The _digest_ 45 | # parameter specifies the digest algorithm to use. This may be a String 46 | # representing the algorithm name or an instance of OpenSSL::Digest. 47 | # 48 | # === Example 49 | # key = 'key' 50 | # data = 'The quick brown fox jumps over the lazy dog' 51 | # 52 | # hmac = OpenSSL::HMAC.hexdigest('SHA1', key, data) 53 | # #=> "de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9" 54 | def hexdigest(digest, key, data) 55 | hmac = new(key, digest) 56 | hmac << data 57 | hmac.hexdigest 58 | end unless method_defined?(:hexdigest) # JRuby 59 | 60 | # :call-seq: 61 | # HMAC.base64digest(digest, key, data) -> aString 62 | # 63 | # Returns the authentication code as a Base64-encoded string. The _digest_ 64 | # parameter specifies the digest algorithm to use. This may be a String 65 | # representing the algorithm name or an instance of OpenSSL::Digest. 66 | # 67 | # === Example 68 | # key = 'key' 69 | # data = 'The quick brown fox jumps over the lazy dog' 70 | # 71 | # hmac = OpenSSL::HMAC.base64digest('SHA1', key, data) 72 | # #=> "3nybhbi3iqa8ino29wqQcBydtNk=" 73 | def base64digest(digest, key, data) 74 | [digest(digest, key, data)].pack("m0") 75 | end 76 | end 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /lib/openssl/marshal.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | #-- 3 | # = Ruby-space definitions to add DER (de)serialization to classes 4 | # 5 | # = Info 6 | # 'OpenSSL for Ruby 2' project 7 | # Copyright (C) 2002 Michal Rokos 8 | # All rights reserved. 9 | # 10 | # = Licence 11 | # This program is licensed under the same licence as Ruby. 12 | # (See the file 'LICENCE'.) 13 | #++ 14 | module OpenSSL 15 | module Marshal 16 | def self.included(base) 17 | base.extend(ClassMethods) 18 | end 19 | 20 | module ClassMethods 21 | def _load(string) 22 | new(string) 23 | end 24 | end 25 | 26 | def _dump(_level) 27 | to_der 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /lib/openssl/pkcs5.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | #-- 3 | # Ruby/OpenSSL Project 4 | # Copyright (C) 2017 Ruby/OpenSSL Project Authors 5 | #++ 6 | 7 | # module OpenSSL 8 | # module PKCS5 9 | # module_function 10 | # 11 | # # OpenSSL::PKCS5.pbkdf2_hmac has been renamed to OpenSSL::KDF.pbkdf2_hmac. 12 | # # This method is provided for backwards compatibility. 13 | # def pbkdf2_hmac(pass, salt, iter, keylen, digest) 14 | # OpenSSL::KDF.pbkdf2_hmac(pass, salt: salt, iterations: iter, 15 | # length: keylen, hash: digest) 16 | # end 17 | # 18 | # def pbkdf2_hmac_sha1(pass, salt, iter, keylen) 19 | # pbkdf2_hmac(pass, salt, iter, keylen, "sha1") 20 | # end 21 | # end 22 | # end 23 | -------------------------------------------------------------------------------- /lib/openssl/pkey.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | #-- 3 | # Ruby/OpenSSL Project 4 | # Copyright (C) 2017 Ruby/OpenSSL Project Authors 5 | #++ 6 | 7 | require_relative 'marshal' 8 | 9 | module OpenSSL::PKey 10 | class DH 11 | include OpenSSL::Marshal 12 | end 13 | 14 | class DSA 15 | include OpenSSL::Marshal 16 | end 17 | 18 | if defined?(EC) 19 | class EC 20 | include OpenSSL::Marshal 21 | end 22 | class EC::Point 23 | # :call-seq: 24 | # point.to_bn([conversion_form]) -> OpenSSL::BN 25 | # 26 | # Returns the octet string representation of the EC point as an instance of 27 | # OpenSSL::BN. 28 | # 29 | # If _conversion_form_ is not given, the _point_conversion_form_ attribute 30 | # set to the group is used. 31 | # 32 | # See #to_octet_string for more information. 33 | # def to_bn(conversion_form = group.point_conversion_form) 34 | # OpenSSL::BN.new(to_octet_string(conversion_form), 2) 35 | # end 36 | end 37 | end 38 | 39 | class RSA 40 | include OpenSSL::Marshal 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/ExtConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Karol Bucek. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | */ 8 | package org.jruby.ext.openssl; 9 | 10 | import org.jruby.Ruby; 11 | import org.jruby.RubyModule; 12 | 13 | /** 14 | * OpenSSL::ExtConfig (emulation) 15 | * 16 | * @author kares 17 | */ 18 | public class ExtConfig { 19 | 20 | static void create(Ruby runtime, RubyModule OpenSSL) { 21 | RubyModule ExtConfig = OpenSSL.defineModuleUnder("ExtConfig"); 22 | ExtConfig.defineAnnotatedMethods(ExtConfig.class); 23 | 24 | ExtConfig.setConstant("OPENSSL_NO_SOCK", runtime.getNil()); // true/false (default) on MRI 25 | // TODO: we really should attempt to detect whether we support this : 26 | ExtConfig.setConstant("TLS_DH_anon_WITH_AES_256_GCM_SHA384", runtime.getFalse()); 27 | ExtConfig.setConstant("HAVE_TLSEXT_HOST_NAME", runtime.getTrue()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/KDF.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2018 Karol Bucek LTD. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jruby.ext.openssl; 25 | 26 | import java.security.InvalidKeyException; 27 | import java.security.NoSuchAlgorithmException; 28 | 29 | import org.jruby.*; 30 | import org.jruby.anno.JRubyMethod; 31 | import org.jruby.anno.JRubyModule; 32 | import org.jruby.exceptions.RaiseException; 33 | import org.jruby.runtime.ThreadContext; 34 | import org.jruby.runtime.builtin.IRubyObject; 35 | 36 | import static org.jruby.ext.openssl.Utils.extractKeywordArgs; 37 | 38 | /** 39 | * Provides functionality of various KDFs (key derivation function). 40 | * 41 | * @author kares 42 | */ 43 | @JRubyModule(name = "OpenSSL::KDF") 44 | public class KDF { 45 | 46 | static void createKDF(final Ruby runtime, final RubyModule OpenSSL, final RubyClass OpenSSLError) { 47 | RubyModule KDF = OpenSSL.defineModuleUnder("KDF"); 48 | KDF.defineClassUnder("KDFError", OpenSSLError, OpenSSLError.getAllocator()); 49 | KDF.defineAnnotatedMethods(KDF.class); 50 | } 51 | 52 | private static final String[] PBKDF2_ARGS = new String[] { "salt", "iterations", "length", "hash" }; 53 | 54 | @JRubyMethod(module = true) // pbkdf2_hmac(pass, salt:, iterations:, length:, hash:) 55 | public static IRubyObject pbkdf2_hmac(ThreadContext context, IRubyObject self, IRubyObject pass, IRubyObject opts) { 56 | IRubyObject[] args = extractKeywordArgs(context, (RubyHash) opts, PBKDF2_ARGS, 1); 57 | args[0] = pass; 58 | try { 59 | return PKCS5.pbkdf2Hmac(context.runtime, args); 60 | } 61 | catch (NoSuchAlgorithmException|InvalidKeyException e) { 62 | throw newKDFError(context.runtime, e.getMessage()); 63 | } 64 | } 65 | 66 | static RaiseException newKDFError(Ruby runtime, String message) { 67 | return Utils.newError(runtime, _KDF(runtime).getClass("KDFError"), message); 68 | } 69 | 70 | static RubyClass _KDF(final Ruby runtime) { 71 | return (RubyClass) runtime.getModule("OpenSSL").getConstant("KDF"); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/OSSLLibrary.java: -------------------------------------------------------------------------------- 1 | package org.jruby.ext.openssl; 2 | 3 | import org.jruby.Ruby; 4 | import org.jruby.runtime.load.Library; 5 | 6 | import java.io.IOException; 7 | 8 | /** 9 | * @deprecated 10 | * @see OpenSSL 11 | */ 12 | public class OSSLLibrary implements Library { 13 | 14 | public static void load(final Ruby runtime) { 15 | OpenSSL.load(runtime); 16 | } 17 | 18 | @Override 19 | public void load(Ruby runtime, boolean wrap) throws IOException { 20 | load(runtime); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/Attribute.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | import org.bouncycastle.asn1.ASN1Encodable; 31 | import java.util.List; 32 | import java.util.ArrayList; 33 | 34 | /** X509_ATTRIBUTE 35 | * 36 | * @author Ola Bini 37 | */ 38 | public class Attribute { 39 | private int type; 40 | private boolean single; 41 | private List set; 42 | 43 | private Attribute() {} 44 | 45 | public static Attribute create(int nid, int atrtype, ASN1Encodable value) { 46 | Attribute ret = new Attribute(); 47 | 48 | ret.type = nid; 49 | ret.single = false; 50 | ret.set = new ArrayList(); 51 | ret.set.add(value); 52 | 53 | return ret; 54 | } 55 | 56 | public int getType() { 57 | return type; 58 | } 59 | 60 | public List getSet() { 61 | return set; 62 | } 63 | 64 | public boolean isSingle() { 65 | return this.single; 66 | } 67 | 68 | @Override 69 | public boolean equals(Object obj) { 70 | boolean ret = this == obj; 71 | if(!ret && (obj instanceof Attribute)) { 72 | Attribute attr2 = (Attribute)obj; 73 | ret = 74 | this.type == attr2.type && 75 | this.set.equals(attr2.set); 76 | } 77 | return ret; 78 | } 79 | 80 | @Override 81 | public int hashCode() { 82 | final int prime = 31; 83 | int result = 1; 84 | result = prime * result + ((set == null) ? 0 : set.hashCode()); 85 | result = prime * result + type; 86 | return result; 87 | } 88 | }// Attribute 89 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/BIOFilter.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | /** 31 | * 32 | * @author Ola Bini 33 | */ 34 | public abstract class BIOFilter extends BIO { 35 | public int getType() { 36 | return TYPE_FILTER; 37 | } 38 | }// BIOFilter 39 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/Base64BIOFilter.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | import java.io.IOException; 31 | import java.io.InputStream; 32 | import java.io.OutputStream; 33 | 34 | /** 35 | * 36 | * @author Ola Bini 37 | */ 38 | public class Base64BIOFilter extends BIOFilter { 39 | private OutputStream nextOutput; 40 | private InputStream nextInput; 41 | 42 | @Override 43 | public int write(byte[] out, int offset, int len) throws IOException { 44 | this.nextOutput.write(out, offset, len); 45 | return len; 46 | } 47 | 48 | @Override 49 | public int read(byte[] into, int offset, int len) throws IOException { 50 | int read = this.nextInput.read(into, offset, len); 51 | if(read == -1) { 52 | return 0; 53 | } 54 | return read; 55 | } 56 | 57 | @Override 58 | public void flush() throws IOException { 59 | this.nextOutput.flush(); 60 | } 61 | 62 | @Override 63 | public BIO push(BIO bio) { 64 | BIO ret = super.push(bio); 65 | this.nextOutput = new Base64.OutputStream(BIO.asOutputStream(this.nextBio)); 66 | this.nextInput = new Base64.InputStream(BIO.asInputStream(this.nextBio)); 67 | return ret; 68 | } 69 | 70 | @Override 71 | public int getType() { 72 | return TYPE_BASE64; 73 | } 74 | }// Base64BIOFilter 75 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/CipherSpec.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2009 Hiroshi Nakamura 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | import javax.crypto.Cipher; 31 | 32 | /** 33 | * 34 | * @author Ola Bini 35 | */ 36 | public class CipherSpec extends BIOFilter { 37 | private final Cipher cipher; 38 | private final String osslName; 39 | private final int keyLenInBits; 40 | 41 | public CipherSpec(Cipher cipher, String osslName, int keyLenInBits) { 42 | this.cipher = cipher; 43 | this.osslName = osslName; 44 | this.keyLenInBits = keyLenInBits; 45 | } 46 | 47 | public Cipher getCipher() { 48 | return cipher; 49 | } 50 | 51 | public String getOsslName() { 52 | return osslName; 53 | } 54 | 55 | public int getKeyLenInBits() { 56 | return keyLenInBits; 57 | } 58 | 59 | public String getAlgorithm() { 60 | return getCipher().getAlgorithm(); 61 | } 62 | 63 | public String getWrappingAlgorithm() { 64 | return getWrappingAlgorithm(getAlgorithm()); 65 | } 66 | 67 | public static String getWrappingAlgorithm(String algorithm) { 68 | if (algorithm == null) { 69 | return null; 70 | } 71 | if (algorithm.equalsIgnoreCase("RSA")) { 72 | return "RSA/ECB/PKCS1Padding"; 73 | } else { 74 | return algorithm; 75 | } 76 | } 77 | 78 | }// CipherSpec 79 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/ECPrivateKeyWithName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Karol Bucek. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | */ 8 | package org.jruby.ext.openssl.impl; 9 | 10 | import java.math.BigInteger; 11 | import java.security.interfaces.ECPrivateKey; 12 | import java.security.spec.ECParameterSpec; 13 | import org.bouncycastle.asn1.ASN1ObjectIdentifier; 14 | 15 | /** 16 | * a trick to keep the curve name around 17 | * (since {@link java.security.KeyPair} is final). 18 | * 19 | * @author kares 20 | */ 21 | public final class ECPrivateKeyWithName implements ECPrivateKey { 22 | 23 | private final ECPrivateKey realKey; 24 | // private final String curveNameId; 25 | private final ASN1ObjectIdentifier curveNameOID; 26 | 27 | public static ECPrivateKeyWithName wrap(ECPrivateKey realKey, ASN1ObjectIdentifier nameOID) { 28 | return new ECPrivateKeyWithName(realKey, nameOID); 29 | } 30 | 31 | private ECPrivateKeyWithName(ECPrivateKey realKey, ASN1ObjectIdentifier nameOID) { 32 | this.realKey = realKey; this.curveNameOID = nameOID; 33 | } 34 | 35 | //private ECPrivateKeyWithName(ECPrivateKey realKey, String curveNameId) { 36 | // this.realKey = realKey; 37 | // this.curveNameId = curveNameId; 38 | //} 39 | 40 | //public String getCurveNameId() { 41 | // return curveNameId; 42 | //} 43 | 44 | public ASN1ObjectIdentifier getCurveNameOID() { 45 | return curveNameOID; 46 | } 47 | 48 | public ECPrivateKey unwrap() { 49 | return realKey; 50 | } 51 | 52 | public BigInteger getS() { 53 | return realKey.getS(); 54 | } 55 | 56 | public String getAlgorithm() { 57 | return realKey.getAlgorithm(); 58 | } 59 | 60 | public String getFormat() { 61 | return realKey.getFormat(); 62 | } 63 | 64 | public byte[] getEncoded() { 65 | return realKey.getEncoded(); 66 | } 67 | 68 | public ECParameterSpec getParams() { 69 | return realKey.getParams(); 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return realKey.toString(); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/Encrypt.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | /** PKCS7_ENCRYPT 31 | * 32 | * @author Ola Bini 33 | */ 34 | public class Encrypt { 35 | private int version; 36 | 37 | /** 38 | * Describe encContent here. 39 | */ 40 | private EncContent encData = new EncContent(); 41 | 42 | /** 43 | * Get the Version value. 44 | * 45 | * @return an int value 46 | */ 47 | public final int getVersion() { 48 | return version; 49 | } 50 | 51 | /** 52 | * Set the Version value. 53 | * 54 | * @param newVersion The new Version value. 55 | */ 56 | public final void setVersion(final int newVersion) { 57 | this.version = newVersion; 58 | } 59 | 60 | /** 61 | * Get the EncData value. 62 | * 63 | * @return an EncContent value 64 | */ 65 | public final EncContent getEncData() { 66 | return encData; 67 | } 68 | 69 | /** 70 | * Set the EncData value. 71 | * 72 | * @param newEncContent The new EncContent value. 73 | */ 74 | public final void setEncData(final EncContent newEncData) { 75 | this.encData = newEncData; 76 | } 77 | }// Encrypt 78 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/IssuerAndSerial.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | /** PKCS7_ISSUER_AND_SERIAL 31 | * 32 | * @author Ola Bini 33 | */ 34 | public class IssuerAndSerial { 35 | }// IssuerAndSerial 36 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/MessageDigestBIOFilter.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | import java.io.IOException; 31 | import java.security.MessageDigest; 32 | 33 | /** 34 | * 35 | * @author Ola Bini 36 | */ 37 | public class MessageDigestBIOFilter extends BIOFilter { 38 | private MessageDigest md; 39 | 40 | public MessageDigestBIOFilter(MessageDigest md) { 41 | this.md = md; 42 | } 43 | 44 | public int gets(byte[] in, int len) throws IOException { 45 | int read = next().gets(in, len); 46 | if(read > 0) { 47 | md.update(in, 0, read); 48 | } 49 | return read; 50 | } 51 | 52 | public int read(byte[] into, int offset, int len) throws IOException { 53 | int read = next().read(into, offset, len); 54 | if(read > 0) { 55 | md.update(into, offset, read); 56 | } 57 | return read; 58 | } 59 | 60 | public int write(byte[] out, int offset, int len) throws IOException { 61 | int written = next().write(out, offset, len); 62 | md.update(out, offset, written); 63 | return written; 64 | } 65 | 66 | public int getType() { 67 | return TYPE_MD; 68 | } 69 | 70 | /** c: BIO_get_md_ctx 71 | * 72 | */ 73 | public MessageDigest getMessageDigest() { 74 | return md; 75 | } 76 | }// MessageDigestBIOFilter 77 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/MimeParam.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | /** MIME_PARAM 31 | * 32 | * @author Ola Bini 33 | */ 34 | public class MimeParam { 35 | private String paramName; 36 | private String paramValue; 37 | 38 | public MimeParam(String name, String value) { 39 | this.paramName = (name == null) ? 40 | null : 41 | name.toLowerCase(); 42 | this.paramValue = value; 43 | } 44 | 45 | public String getParamName() { 46 | return this.paramName; 47 | } 48 | 49 | public String getParamValue() { 50 | return this.paramValue; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object other) { 55 | boolean ret = this == other; 56 | if(!ret && (other instanceof MimeParam)) { 57 | MimeParam mh = (MimeParam)other; 58 | ret = 59 | ((this.paramName == null) ? mh.paramName == null : this.paramName.equals(mh.paramName)) && 60 | ((this.paramValue == null) ? mh.paramValue == null : this.paramValue.equals(mh.paramValue)); 61 | } 62 | return ret; 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | final int prime = 31; 68 | int result = 1; 69 | result = prime * result 70 | + ((paramName == null) ? 0 : paramName.hashCode()); 71 | result = prime * result 72 | + ((paramValue == null) ? 0 : paramValue.hashCode()); 73 | return result; 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "#"; 79 | } 80 | }// MimeParam 81 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/NotVerifiedPKCS7Exception.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | /** 31 | * 32 | * @author Ola Bini 33 | */ 34 | public class NotVerifiedPKCS7Exception extends PKCS7Exception { 35 | private static final long serialVersionUID = 1L; 36 | 37 | public NotVerifiedPKCS7Exception() { 38 | super(-1, -1); 39 | } 40 | 41 | public NotVerifiedPKCS7Exception(Exception cause) { 42 | super(-1, -1, cause); 43 | } 44 | }// NotVerifiedPKCS7Exception 45 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/NullSinkBIO.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | import java.io.IOException; 31 | 32 | /** 33 | * 34 | * @author Ola Bini 35 | */ 36 | public class NullSinkBIO extends BIO { 37 | public int gets(byte[] in, int len) throws IOException { 38 | return 0; 39 | } 40 | 41 | public int write(byte[] out, int offset, int len) throws IOException { 42 | return len; 43 | } 44 | 45 | public int read(byte[] into, int offset, int len) throws IOException { 46 | return 0; 47 | } 48 | 49 | public int getType() { 50 | return TYPE_NULL; 51 | } 52 | }// NullSinkBIO 53 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/PKCS7DataData.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | import java.util.Arrays; 31 | import org.bouncycastle.asn1.ASN1Encodable; 32 | import org.bouncycastle.asn1.ASN1OctetString; 33 | import org.bouncycastle.asn1.DEROctetString; 34 | 35 | /** 36 | * 37 | * @author Ola Bini 38 | */ 39 | public class PKCS7DataData extends PKCS7Data { 40 | /* NID_pkcs7_data */ 41 | private ASN1OctetString data; 42 | 43 | public PKCS7DataData() { 44 | this(new DEROctetString(new byte[0])); 45 | } 46 | 47 | public PKCS7DataData(ASN1OctetString data) { 48 | this.data = data; 49 | } 50 | 51 | @Override 52 | public int getType() { 53 | return ASN1Registry.NID_pkcs7_data; 54 | } 55 | 56 | @Override 57 | public void setData(ASN1OctetString data) { 58 | this.data = data; 59 | } 60 | 61 | @Override 62 | public ASN1OctetString getData() { 63 | return this.data; 64 | } 65 | 66 | @Override 67 | public boolean isData() { 68 | return true; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "#"; 74 | } 75 | 76 | /** 77 | * Data ::= OCTET STRING 78 | */ 79 | public static PKCS7DataData fromASN1(ASN1Encodable content) { 80 | if ( content == null ) return new PKCS7DataData(); 81 | return new PKCS7DataData((ASN1OctetString) content); 82 | } 83 | 84 | @Override 85 | public ASN1Encodable asASN1() { 86 | if ( data == null ) { 87 | return new DEROctetString(new byte[0]).toASN1Primitive(); 88 | } 89 | return data.toASN1Primitive(); 90 | } 91 | }// PKCS7DataData 92 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/PKCS7DataDigest.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | import org.bouncycastle.asn1.ASN1Encodable; 31 | 32 | /** 33 | * 34 | * @author Ola Bini 35 | */ 36 | public class PKCS7DataDigest extends PKCS7Data { 37 | /* NID_pkcs7_digest */ 38 | private Digest digest; 39 | 40 | public PKCS7DataDigest() { 41 | this.digest = new Digest(); 42 | this.digest.setVersion(0); 43 | } 44 | 45 | public int getType() { 46 | return ASN1Registry.NID_pkcs7_digest; 47 | } 48 | 49 | public Digest getDigest() { 50 | return this.digest; 51 | } 52 | 53 | public boolean isDigest() { 54 | return true; 55 | } 56 | 57 | public void setContent(PKCS7 p7) { 58 | this.digest.setContents(p7); 59 | } 60 | 61 | public static PKCS7DataDigest fromASN1(ASN1Encodable content) { 62 | throw new UnsupportedOperationException("TODO: can't create DataDigest from ASN1 yet"); 63 | } 64 | }// PKCS7DataDigest 65 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/PKCS7DataEncrypted.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | import org.bouncycastle.asn1.ASN1Encodable; 31 | 32 | /** 33 | * 34 | * @author Ola Bini 35 | */ 36 | public class PKCS7DataEncrypted extends PKCS7Data { 37 | /* NID_pkcs7_encrypted */ 38 | private Encrypt encrypted; 39 | 40 | public PKCS7DataEncrypted() { 41 | this.encrypted = new Encrypt(); 42 | this.encrypted.setVersion(0); 43 | this.encrypted.getEncData().setContentType(ASN1Registry.NID_pkcs7_data); 44 | } 45 | 46 | public int getType() { 47 | return ASN1Registry.NID_pkcs7_encrypted; 48 | } 49 | 50 | public Encrypt getEncrypted() { 51 | return this.encrypted; 52 | } 53 | 54 | public boolean isEncrypted() { 55 | return true; 56 | } 57 | 58 | public static PKCS7DataEncrypted fromASN1(ASN1Encodable content) { 59 | throw new UnsupportedOperationException("TODO: can't create DataEncrypted from ASN1 yet"); 60 | } 61 | }// PKCS7DataEncrypted 62 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/PKCS7DataEnveloped.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | 31 | import org.bouncycastle.asn1.ASN1Encodable; 32 | 33 | /** 34 | * 35 | * @author Ola Bini 36 | */ 37 | public class PKCS7DataEnveloped extends PKCS7Data { 38 | /* NID_pkcs7_enveloped */ 39 | private Envelope enveloped; 40 | 41 | public PKCS7DataEnveloped() { 42 | this.enveloped = new Envelope(); 43 | this.enveloped.setVersion(0); 44 | this.enveloped.getEncData().setContentType(ASN1Registry.NID_pkcs7_data); 45 | } 46 | 47 | public PKCS7DataEnveloped(Envelope enveloped) { 48 | this.enveloped = enveloped; 49 | } 50 | 51 | public int getType() { 52 | return ASN1Registry.NID_pkcs7_enveloped; 53 | } 54 | 55 | @Override 56 | public Envelope getEnveloped() { 57 | return this.enveloped; 58 | } 59 | 60 | @Override 61 | public boolean isEnveloped() { 62 | return true; 63 | } 64 | 65 | @Override 66 | public void setCipher(CipherSpec cipher) { 67 | this.enveloped.getEncData().setCipher(cipher); 68 | } 69 | 70 | @Override 71 | public void addRecipientInfo(RecipInfo ri) { 72 | this.enveloped.getRecipientInfo().add(ri); 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return this.enveloped.toString(); 78 | } 79 | 80 | public static PKCS7DataEnveloped fromASN1(ASN1Encodable content) { 81 | return new PKCS7DataEnveloped(Envelope.fromASN1(content)); 82 | } 83 | 84 | @Override 85 | public ASN1Encodable asASN1() { 86 | return enveloped.asASN1(); 87 | } 88 | }// PKCS7DataEnveloped 89 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/PKCS7Exception.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | /** 31 | * 32 | * @author Ola Bini 33 | */ 34 | public class PKCS7Exception extends Exception { 35 | private static final long serialVersionUID = 1L; 36 | 37 | private int method; 38 | private int reason; 39 | private String errorData; 40 | 41 | public PKCS7Exception(int method, int reason) { 42 | this(method, reason, (String) null); 43 | } 44 | 45 | public PKCS7Exception(int method, int reason, String errorData) { 46 | super("PKCS7[Method: " + method + ", Reason: " + reason + ", Data: " + errorData + "]"); 47 | this.method = method; 48 | this.reason = reason; 49 | this.errorData = errorData; 50 | } 51 | 52 | public PKCS7Exception(int method, int reason, Throwable cause) { 53 | super("PKCS7[Method: " + method + ", Reason: " + reason + "]", cause); 54 | this.method = method; 55 | this.reason = reason; 56 | this.errorData = cause != null ? cause.getMessage() : null; 57 | } 58 | 59 | public int getMethod() { 60 | return this.method; 61 | } 62 | 63 | public int getReason() { 64 | return this.reason; 65 | } 66 | 67 | public String getErrorData() { 68 | return this.errorData; 69 | } 70 | }// PKCS7Exception 71 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/TypeDiscriminating.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2008 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.impl; 29 | 30 | /** 31 | * @author Ola Bini 32 | */ 33 | public abstract class TypeDiscriminating { 34 | }// TypeDiscriminating 35 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/impl/pem/MiscPEMGeneratorHelper.java: -------------------------------------------------------------------------------- 1 | package org.jruby.ext.openssl.impl.pem; 2 | 3 | import org.bouncycastle.openssl.EncryptionException; 4 | import org.bouncycastle.openssl.MiscPEMGenerator; 5 | import org.bouncycastle.openssl.PEMEncryptor; 6 | 7 | import java.security.SecureRandom; 8 | 9 | /** 10 | * @author kares 11 | */ 12 | public abstract class MiscPEMGeneratorHelper { 13 | 14 | public static MiscPEMGenerator newGenerator(final Object obj, 15 | final String algorithm, final char[] password, final SecureRandom random) { 16 | return new MiscPEMGenerator(obj, buildPEMEncryptor(algorithm, password, random)); 17 | } 18 | 19 | private static PEMEncryptor buildPEMEncryptor(final String algorithm, 20 | final char[] password, final SecureRandom random) { 21 | 22 | int ivLength = algorithm.toUpperCase().startsWith("AES-") ? 16 : 8; 23 | final byte[] iv = new byte[ivLength]; 24 | ( random == null ? new SecureRandom() : random ).nextBytes(iv); 25 | 26 | return new PEMEncryptor() { 27 | public String getAlgorithm() { return algorithm; } 28 | 29 | public byte[] getIV() { return iv; } 30 | 31 | public byte[] encrypt(byte[] encoding) throws EncryptionException { 32 | return PEMUtilities.crypt(true, encoding, password, algorithm, iv); 33 | } 34 | }; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/util/ByteArrayOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 kares. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | */ 8 | package org.jruby.ext.openssl.util; 9 | 10 | /** 11 | * Allows direct buffer access for less copy-ing. 12 | * 13 | * @author kares 14 | */ 15 | public final class ByteArrayOutputStream extends java.io.ByteArrayOutputStream { 16 | 17 | public ByteArrayOutputStream() { 18 | super(); 19 | } 20 | 21 | public ByteArrayOutputStream(int size) { 22 | super(size); 23 | } 24 | 25 | public byte[] buffer() { 26 | return buf; 27 | } 28 | 29 | public int size() { 30 | return count; 31 | } 32 | 33 | @Override 34 | public byte[] toByteArray() { 35 | final int len = buf.length; 36 | if (count == len) return buf; // no-copying 37 | 38 | final byte[] copy = new byte[count]; 39 | System.arraycopy(buf, 0, copy, 0, count); 40 | return copy; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/CRL.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | import java.security.cert.X509CRL; 31 | 32 | /** 33 | * c: X509_OBJECT 34 | * 35 | * @author Ola Bini 36 | */ 37 | public class CRL extends X509Object { 38 | 39 | public final java.security.cert.CRL crl; 40 | 41 | public CRL(java.security.cert.CRL crl) { 42 | this.crl = crl; 43 | } 44 | 45 | @Override 46 | public int type() { 47 | return X509Utils.X509_LU_CRL; 48 | } 49 | 50 | @Override 51 | public boolean isName(final Name name) { 52 | return name.equalTo( ((X509CRL) crl).getIssuerX500Principal() ); 53 | } 54 | 55 | @Override 56 | public boolean matches(final X509Object other) { 57 | if (other instanceof CRL) { 58 | final X509CRL thisCRL = (X509CRL) crl; 59 | final X509CRL thatCRL = (X509CRL)((CRL) other).crl; 60 | return thisCRL.getIssuerX500Principal().equals( thatCRL.getIssuerX500Principal() ); 61 | } 62 | return false; 63 | } 64 | 65 | @Override 66 | public int compareTo(final X509Object other) { 67 | int cmp = super.compareTo(other); 68 | if (cmp != 0) return cmp; 69 | return crl.equals( ((CRL) other).crl ) ? 0 : -1; 70 | } 71 | 72 | }// X509_OBJECT_CRL 73 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/Certificate.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | /** 31 | * c: X509_OBJECT 32 | * 33 | * @author Ola Bini 34 | */ 35 | public class Certificate extends X509Object { 36 | 37 | public final X509AuxCertificate cert; 38 | 39 | public Certificate(final X509AuxCertificate cert) { 40 | this.cert = cert; 41 | } 42 | 43 | @Override 44 | public int type() { 45 | return X509Utils.X509_LU_X509; 46 | } 47 | 48 | @Override 49 | public boolean isName(final Name name) { 50 | return name.equalToCertificateSubject(cert); 51 | } 52 | 53 | @Override 54 | public boolean matches(final X509Object other) { 55 | if (other instanceof Certificate) { 56 | final Certificate that = (Certificate) other; 57 | if (X509AuxCertificate.equalSubjects(this.cert, that.cert)) { 58 | return this.cert.hashCode() == that.cert.hashCode(); 59 | }; 60 | } 61 | return false; 62 | } 63 | 64 | @Override 65 | public int compareTo(final X509Object other) { 66 | int cmp = super.compareTo(other); 67 | if (cmp != 0) return cmp; 68 | return cert.equals( ((Certificate) other).cert ) ? 0 : -1; 69 | } 70 | 71 | }// X509_OBJECT_CERT 72 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/CertificateFile.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | /** 31 | * Contains information like x509_file_st and X509_CERT_FILER_CTX in 32 | * x509_vfy.h 33 | * 34 | * @author Ola Bini 35 | */ 36 | public class CertificateFile { 37 | public static class Path { 38 | public Path(String name, int type) { 39 | this.name = name; this.type = type; 40 | } 41 | public String name; 42 | public int type; 43 | } 44 | public int numberOfPaths; // This details how many of the paths-var that is actually used 45 | public Path[] paths; 46 | }// X509_CERT_FILE_CTX 47 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/CertificateHashDir.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | /** 31 | * Contains information like x509_hash_dir_st and X509_HASH_DIR_CTX in 32 | * x509_vfy.h 33 | * 34 | * @author Ola Bini 35 | */ 36 | public class CertificateHashDir { 37 | public static class Dir { 38 | public Dir(String name, int type) { 39 | this.name = name; this.type = type; 40 | } 41 | public String name; 42 | public int type; 43 | } 44 | public int numberOfDirs; // This details how many of the dirs-var that is actually used 45 | public Dir[] dirs; 46 | }// X509_HASH_DIR_CTX 47 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/Function0.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | /** 31 | * Zero arity function call. 32 | * 33 | * @author Ola Bini 34 | */ 35 | interface Function0 { 36 | static class Empty implements Function0 { 37 | public int call() { 38 | return -1; 39 | } 40 | } 41 | public static final Function0.Empty EMPTY = new Empty(); 42 | int call() throws Exception; 43 | }// Function0 44 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/Function1.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | /** 31 | * One arity function call. 32 | * 33 | * @author Ola Bini 34 | */ 35 | interface Function1 { 36 | int call(T arg0) throws Exception; 37 | }// Function1 38 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/Function2.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | /** 31 | * Two arity function call. 32 | * 33 | * @author Ola Bini 34 | */ 35 | interface Function2 { 36 | int call(T arg0, U arg1) throws Exception; 37 | }// Function2 38 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/Function3.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | /** 31 | * Three arity function call. 32 | * 33 | * @author Ola Bini 34 | */ 35 | interface Function3 { 36 | int call(T arg0, U arg1, V arg2) throws Exception; 37 | }// Function3 38 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/Function4.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | /** 31 | * Four arity function call. 32 | * 33 | * @author Ola Bini 34 | */ 35 | interface Function4 { 36 | int call(T arg0, U arg1, V arg2, X arg3) throws Exception; 37 | }// Function4 38 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/Function5.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | /** 31 | * Five arity function call. 32 | * 33 | * @author Ola Bini 34 | */ 35 | interface Function5 { 36 | int call(T arg0, U arg1, V arg2, X arg3, Y arg4) throws Exception; 37 | }// Function5 38 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/PKey.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | import java.security.PrivateKey; 31 | 32 | /** 33 | * c: X509_OBJECT 34 | * 35 | * @author Ola Bini 36 | */ 37 | public class PKey extends X509Object { 38 | 39 | public final java.security.PrivateKey pkey; 40 | 41 | public PKey(PrivateKey pkey) { 42 | this.pkey = pkey; 43 | } 44 | 45 | public int type() { 46 | return X509Utils.X509_LU_PKEY; 47 | } 48 | 49 | @Override 50 | public boolean isName(final Name nm) { 51 | return false; 52 | } 53 | 54 | @Override 55 | public boolean matches(final X509Object other) { 56 | if (other instanceof PKey) { 57 | final PKey that = (PKey) other; 58 | return this.pkey.equals( that.pkey ); 59 | } 60 | return false; 61 | } 62 | 63 | }// X509_OBJECT_PKEY 64 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/PolicyTree.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | /** 31 | * c: X509_POLICY_TREE 32 | * 33 | * @author Ola Bini 34 | */ 35 | /*public*/ class PolicyTree { 36 | // not-used 37 | }// X509_POLICY_TREE 38 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/X509Aux.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | import java.util.List; 31 | 32 | import org.bouncycastle.asn1.ASN1Primitive; 33 | 34 | /** 35 | * @author Ola Bini 36 | */ 37 | final class X509Aux { 38 | 39 | final String alias; /* "friendly name" */ 40 | final byte[] keyid; /* key id of private key */ 41 | 42 | final List trust; // String of OID's /* trusted uses */ 43 | final List reject; // String of OID's /* rejected uses */ 44 | final List other; /* String of OID's of sigAlgs, other unspecified info */ 45 | 46 | X509Aux(final String alias, final byte[] keyid, 47 | final List trust, 48 | final List reject, 49 | final List other) { 50 | this.alias = alias; 51 | this.keyid = keyid; 52 | this.trust = trust; 53 | this.reject = reject; 54 | this.other = other; 55 | } 56 | 57 | }// X509_AUX 58 | -------------------------------------------------------------------------------- /src/main/java/org/jruby/ext/openssl/x509store/X509Object.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Ola Bini 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the EPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the EPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jruby.ext.openssl.x509store; 29 | 30 | import java.util.Collection; 31 | import java.util.List; 32 | 33 | /** 34 | * c: X509_OBJECT 35 | * 36 | * @author Ola Bini 37 | */ 38 | public abstract class X509Object implements Comparable { 39 | 40 | /** 41 | * c: X509_OBJECT_idx_by_subject 42 | */ 43 | public static int indexBySubject(final List list, int type, Name name) { 44 | for ( int i = 0; i < list.size(); i++ ) { 45 | final X509Object obj = list.get(i); 46 | if ( type == obj.type() && obj.isName(name) ) return i; 47 | } 48 | return -1; 49 | } 50 | 51 | /** 52 | * c: X509_OBJECT_retrieve_by_subject 53 | */ 54 | public static X509Object retrieveBySubject(final Collection list, int type, Name name) { 55 | for ( X509Object obj : list ) { 56 | if ( type == obj.type() && obj.isName(name) ) return obj; 57 | } 58 | return null; 59 | } 60 | 61 | /** 62 | * c: X509_OBJECT_retrieve_match 63 | */ 64 | public static X509Object retrieveMatch(final Collection list, X509Object x) { 65 | for ( X509Object obj : list ) { 66 | if ( obj.matches(x) ) return obj; 67 | } 68 | return null; 69 | } 70 | 71 | public abstract boolean isName(Name nm) ; 72 | 73 | public abstract boolean matches(X509Object o) ; 74 | 75 | public abstract int type() ; 76 | 77 | public int compareTo(X509Object other) { 78 | return type() - other.type(); 79 | } 80 | 81 | }// X509_OBJECT 82 | -------------------------------------------------------------------------------- /src/test/integration/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'httpclient', :require => false 4 | gem 'trocla', '~> 0.2.3', :require => false 5 | gem 'faraday', '< 2.0', :require => false 6 | gem 'manticore', '>= 0.8.0', :require => false 7 | -------------------------------------------------------------------------------- /src/test/java/org/jruby/ext/openssl/CipherSpiFake.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 Karol Bucek. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jruby.ext.openssl; 25 | 26 | import javax.crypto.*; 27 | import java.security.*; 28 | import java.security.spec.AlgorithmParameterSpec; 29 | 30 | class CipherSpiFake extends CipherSpi { 31 | 32 | @Override 33 | protected void engineSetMode(String s) throws NoSuchAlgorithmException { 34 | 35 | } 36 | 37 | @Override 38 | protected void engineSetPadding(String s) throws NoSuchPaddingException { 39 | 40 | } 41 | 42 | @Override 43 | protected int engineGetBlockSize() { 44 | return 0; 45 | } 46 | 47 | @Override 48 | protected int engineGetOutputSize(int i) { 49 | return 0; 50 | } 51 | 52 | @Override 53 | protected byte[] engineGetIV() { 54 | return new byte[0]; 55 | } 56 | 57 | @Override 58 | protected AlgorithmParameters engineGetParameters() { 59 | return null; 60 | } 61 | 62 | @Override 63 | protected void engineInit(int i, Key key, SecureRandom secureRandom) throws InvalidKeyException { 64 | 65 | } 66 | 67 | @Override 68 | protected void engineInit(int i, Key key, AlgorithmParameterSpec algorithmParameterSpec, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException { 69 | 70 | } 71 | 72 | @Override 73 | protected void engineInit(int i, Key key, AlgorithmParameters algorithmParameters, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException { 74 | 75 | } 76 | 77 | @Override 78 | protected byte[] engineUpdate(byte[] bytes, int i, int i1) { 79 | return new byte[0]; 80 | } 81 | 82 | @Override 83 | protected int engineUpdate(byte[] bytes, int i, int i1, byte[] bytes1, int i2) throws ShortBufferException { 84 | return 0; 85 | } 86 | 87 | @Override 88 | protected byte[] engineDoFinal(byte[] bytes, int i, int i1) throws IllegalBlockSizeException, BadPaddingException { 89 | return new byte[0]; 90 | } 91 | 92 | @Override 93 | protected int engineDoFinal(byte[] bytes, int i, int i1, byte[] bytes1, int i2) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException { 94 | return 0; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/test/java/org/jruby/ext/openssl/SignatureSpiFake.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2014 Karol Bucek. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jruby.ext.openssl; 25 | 26 | import java.security.*; 27 | 28 | /** 29 | * Created by cmeier on 7/29/15. 30 | */ 31 | class SignatureSpiFake extends Signature { 32 | 33 | SignatureSpiFake() { 34 | super("fake"); 35 | } 36 | 37 | @Override 38 | protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException { 39 | 40 | } 41 | 42 | @Override 43 | protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException { 44 | 45 | } 46 | 47 | @Override 48 | protected void engineUpdate(byte b) throws SignatureException { 49 | 50 | } 51 | 52 | @Override 53 | protected void engineUpdate(byte[] b, int off, int len) throws SignatureException { 54 | 55 | } 56 | 57 | @Override 58 | protected byte[] engineSign() throws SignatureException { 59 | return new byte[0]; 60 | } 61 | 62 | @Override 63 | protected boolean engineVerify(byte[] sigBytes) throws SignatureException { 64 | return false; 65 | } 66 | 67 | @Override 68 | protected void engineSetParameter(String param, Object value) throws InvalidParameterException { 69 | 70 | } 71 | 72 | @Override 73 | protected Object engineGetParameter(String param) throws InvalidParameterException { 74 | return null; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/org/jruby/ext/openssl/security/SecurityManager.java: -------------------------------------------------------------------------------- 1 | package org.jruby.ext.openssl.security; 2 | 3 | import org.jruby.Ruby; 4 | import org.jruby.RubyString; 5 | import org.jruby.runtime.builtin.IRubyObject; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class SecurityManager extends java.lang.SecurityManager { 11 | public static class RubyPermission { 12 | private final IRubyObject lambda; 13 | 14 | public RubyPermission(IRubyObject lambda) { 15 | this.lambda = lambda; 16 | } 17 | 18 | public boolean matches(java.security.Permission perm) { 19 | Ruby runtime = lambda.getRuntime(); 20 | 21 | return lambda.callMethod(runtime.getCurrentContext(), 22 | "call", 23 | new IRubyObject[] { 24 | RubyString.newString(runtime, perm.getClass().getSimpleName()), 25 | RubyString.newString(runtime, perm.getName()), 26 | RubyString.newString(runtime, perm.getActions()) 27 | }).isTrue(); 28 | } 29 | } 30 | 31 | /* 32 | public static SecurityManager install() { 33 | SecurityManager manager = new SecurityManager(); 34 | 35 | System.setSecurityManager(manager); 36 | 37 | return manager; 38 | } */ 39 | 40 | private boolean verbose = false; 41 | private boolean strict = false; 42 | private final List temporaryPermissions = new ArrayList(); 43 | 44 | @Override 45 | public void checkPermission(java.security.Permission perm) { 46 | for (RubyPermission permission: temporaryPermissions) { 47 | if (permission.matches(perm)) { 48 | return; 49 | } 50 | } 51 | 52 | if (strict) { 53 | logTrace(perm.toString() + " denied"); 54 | super.checkPermission(perm); 55 | } 56 | } 57 | 58 | public SecurityManager setStrict(boolean strict) { 59 | this.strict = strict; 60 | return this; 61 | } 62 | 63 | public SecurityManager permit(RubyPermission permission) { 64 | temporaryPermissions.add(permission); 65 | return this; 66 | } 67 | 68 | public SecurityManager revoke(RubyPermission permission) { 69 | temporaryPermissions.remove(permission); 70 | return this; 71 | } 72 | 73 | public SecurityManager setVerbosity(boolean verbose) { 74 | this.verbose = verbose; 75 | return this; 76 | } 77 | 78 | private void logTrace(String message) { 79 | if (verbose) { 80 | new Exception(message).printStackTrace(); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/test/ossl/ut_eof.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | 3 | module TestEOF 4 | def test_eof_0 5 | open_file("") {|f| 6 | assert_equal("", f.read(0)) 7 | assert_equal("", f.read(0)) 8 | assert_equal("", f.read) 9 | assert_nil(f.read(0)) 10 | assert_nil(f.read(0)) 11 | } 12 | open_file("") {|f| 13 | assert_nil(f.read(1)) 14 | assert_equal("", f.read) 15 | assert_nil(f.read(1)) 16 | } 17 | open_file("") {|f| 18 | s = "x" 19 | assert_equal("", f.read(nil, s)) 20 | assert_equal("", s) 21 | } 22 | open_file("") {|f| 23 | s = "x" 24 | assert_nil(f.read(10, s)) 25 | assert_equal("", s) 26 | } 27 | end 28 | 29 | def test_eof_0_rw 30 | return unless respond_to? :open_file_rw 31 | open_file_rw("") {|f| 32 | assert_equal("", f.read) 33 | assert_equal("", f.read) 34 | assert_equal(0, f.syswrite("")) 35 | assert_equal("", f.read) 36 | } 37 | end 38 | 39 | def test_eof_1 40 | open_file("a") {|f| 41 | assert_equal("", f.read(0)) 42 | assert_equal("a", f.read(1)) 43 | assert_equal("" , f.read(0)) 44 | assert_equal("" , f.read(0)) 45 | assert_equal("", f.read) 46 | assert_nil(f.read(0)) 47 | assert_nil(f.read(0)) 48 | } 49 | open_file("a") {|f| 50 | assert_equal("a", f.read(1)) 51 | assert_nil(f.read(1)) 52 | } 53 | open_file("a") {|f| 54 | assert_equal("a", f.read(2)) 55 | assert_nil(f.read(1)) 56 | assert_equal("", f.read) 57 | assert_nil(f.read(1)) 58 | } 59 | open_file("a") {|f| 60 | assert_equal("a", f.read) 61 | assert_nil(f.read(1)) 62 | assert_equal("", f.read) 63 | assert_nil(f.read(1)) 64 | } 65 | open_file("a") {|f| 66 | assert_equal("a", f.read(2)) 67 | assert_equal("", f.read) 68 | assert_equal("", f.read) 69 | } 70 | open_file("a") {|f| 71 | assert_equal("a", f.read) 72 | assert_nil(f.read(0)) 73 | } 74 | open_file("a") {|f| 75 | s = "x" 76 | assert_equal("a", f.read(nil, s)) 77 | assert_equal("a", s) 78 | } 79 | open_file("a") {|f| 80 | s = "x" 81 | assert_equal("a", f.read(10, s)) 82 | assert_equal("a", s) 83 | } 84 | end 85 | 86 | def test_eof_2 87 | open_file("") {|f| 88 | assert_equal("", f.read) 89 | assert(f.eof?) 90 | } 91 | end 92 | 93 | def test_eof_3 94 | open_file("") {|f| 95 | assert(f.eof?) 96 | } 97 | end 98 | 99 | module Seek 100 | def open_file_seek(content, pos) 101 | open_file(content) do |f| 102 | f.seek(pos) 103 | yield f 104 | end 105 | end 106 | 107 | def test_eof_0_seek 108 | open_file_seek("", 10) {|f| 109 | assert_equal(10, f.pos) 110 | assert_equal("", f.read(0)) 111 | assert_equal("", f.read) 112 | assert_nil(f.read(0)) 113 | assert_equal("", f.read) 114 | } 115 | end 116 | 117 | def test_eof_1_seek 118 | open_file_seek("a", 10) {|f| 119 | assert_equal("", f.read) 120 | assert_equal("", f.read) 121 | } 122 | open_file_seek("a", 1) {|f| 123 | assert_equal("", f.read) 124 | assert_equal("", f.read) 125 | } 126 | end 127 | end 128 | end 129 | -------------------------------------------------------------------------------- /src/test/ruby/dsa/private_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN DSA PRIVATE KEY----- 2 | MIIBugIBAAKBgQDpdW60slBJrsrXrsputlqXFlT70CA0czpJZWbppiv4fed941TN 3 | /v/ICLjrNcsWXMbU5hb4faPrMZpAbUuIK+tMtJzz7sWMiINtso1FlQE/sUYBFqCv 4 | Tmkj52N0dPGsE7qmZ6ZknaJn6DbrAL569+5NIe9CR6cTtwL4IPWVXT3HQQIVAJqv 5 | o3Yrj85paNmGTIZfVt/oymAFAoGAb+S//7DQc6S/AK6r26BpQ/C4swSx1MTSl490 6 | hBJw0Czns5djqz9QB6ELufshGES1gcDGrYIncxQTGw1tPoJVrA+kefPVbRaYs2qM 7 | HasEfM1GfILfu4XDBB4xAoFryjKizOu8MwEXTsPLiTe9MdiT90NfcgSyIty1FgFP 8 | ZSz0JLMCgYBmAYli6D4DGB05NCVXBWPiu42c78gGCgibrbvCXpozB22TdMWA41ho 9 | 7Oy7diBJLuJPUdmSsK++RE0bxlDl6QfmxTqfdb0ZUZ4u2bC9VeSM8ZtkbtxRpJGU 10 | p6znJdL83f05H2bhkKWI6a+vj894wRbtj+ube2UZPgKHFvkgdv732QIUKPp2Kkq+ 11 | UQDoq2xu7v84G0sFIhc= 12 | -----END DSA PRIVATE KEY----- 13 | -------------------------------------------------------------------------------- /src/test/ruby/ec/base64.rb: -------------------------------------------------------------------------------- 1 | require 'base64' 2 | 3 | Base64.module_eval do 4 | 5 | def self.strict_encode64(bin) 6 | [ bin ].pack("m0") 7 | end unless defined? Base64.strict_encode64 8 | 9 | def self.urlsafe_encode64(bin) 10 | strict_encode64(bin).tr("+/", "-_") 11 | end unless defined? Base64.urlsafe_encode64 12 | 13 | def self.strict_decode64(str) 14 | str.unpack("m0").first 15 | end unless defined? Base64.strict_decode64 16 | 17 | def self.urlsafe_decode64(str) 18 | strict_decode64(str.tr("-_", "+/")) 19 | end unless defined? Base64.urlsafe_decode64 20 | 21 | end -------------------------------------------------------------------------------- /src/test/ruby/ec/hkdf.rb: -------------------------------------------------------------------------------- 1 | require 'stringio' 2 | 3 | class HKDF 4 | DefaultAlgorithm = 'SHA256' 5 | DefaultReadSize = 512 * 1024 6 | 7 | def initialize(source, options = {}) 8 | source = StringIO.new(source) if source.is_a?(String) 9 | 10 | algorithm = options.fetch(:algorithm, DefaultAlgorithm) 11 | @digest = OpenSSL::Digest.new(algorithm) 12 | @info = options.fetch(:info, '') 13 | 14 | salt = options[:salt] 15 | salt = 0.chr * @digest.digest_length if salt.nil? or salt.empty? 16 | read_size = options.fetch(:read_size, DefaultReadSize) 17 | 18 | @prk = _generate_prk(salt, source, read_size) 19 | @position = 0 20 | @blocks = [] 21 | @blocks << '' 22 | end 23 | 24 | def algorithm 25 | @digest.name 26 | end 27 | 28 | def max_length 29 | @max_length ||= @digest.digest_length * 255 30 | end 31 | 32 | def seek(position) 33 | raise RangeError.new("cannot seek past #{max_length}") if position > max_length 34 | 35 | @position = position 36 | end 37 | 38 | def rewind 39 | seek(0) 40 | end 41 | 42 | def next_bytes(length) 43 | new_position = length + @position 44 | raise RangeError.new("requested #{length} bytes, only #{max_length} available") if new_position > max_length 45 | 46 | _generate_blocks(new_position) 47 | 48 | start = @position 49 | @position = new_position 50 | 51 | @blocks.join('').slice(start, length) 52 | end 53 | 54 | def next_hex_bytes(length) 55 | next_bytes(length).unpack('H*').first 56 | end 57 | 58 | def _generate_prk(salt, source, read_size) 59 | hmac = OpenSSL::HMAC.new(salt, @digest) 60 | while block = source.read(read_size) 61 | hmac.update(block) 62 | end 63 | hmac.digest 64 | end 65 | 66 | def _generate_blocks(length) 67 | start = @blocks.size 68 | block_count = (length.to_f / @digest.digest_length).ceil 69 | start.upto(block_count) do |n| 70 | @blocks << OpenSSL::HMAC.digest(@digest, @prk, @blocks[n - 1] + @info + n.chr) 71 | end 72 | end 73 | end 74 | 75 | -------------------------------------------------------------------------------- /src/test/ruby/ec/private_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MD4CAQEEDrtUuJOpUTwJpjf3LJUuoAcGBSuBBAAGoSADHgAEe2LZ/iq6+RafJRYv 3 | bkJPniq3aSf9nv1Xu+DMMg== 4 | -----END EC PRIVATE KEY----- 5 | -------------------------------------------------------------------------------- /src/test/ruby/ec/private_key2.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MIHaAgEBBEAJF2SrSI8nWVc9JR3qfvmwBpCmb0x5XUc8Tzc1KZ4DtJrg+5Ut6vQR 3 | QK7YIZifynst7q7DODVhgf/D16L8069GoAsGCSskAwMCCAEBDqGBhQOBggAEB/T1 4 | u6sxFny3OW83HXVFXaBUkJtkyByyb3HNuFXSshr3VAozUbHtB8avShcy2jBTULd3 5 | FOzTj5R/ME5egOG1fTMQRSxM85r/cSKFguiJkZGGWETwXvlJ7LRhy5GSeV2fgwLV 6 | TS/ljdy6ho/E+pfViDqIZa+FSTBhbB67TZlbJQw= 7 | -----END EC PRIVATE KEY----- 8 | -------------------------------------------------------------------------------- /src/test/ruby/ec/private_key_pkcs8.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgUmgU1rG7E9WJmB4A 3 | D1RZ+PP+aYEH2ZZxWTGVR0gDr/qhRANCAAR5d0hOX+W8RznN62sAzIeozl4OBl6K 4 | nKdpKKiZTAua05NCaWJR5mGnrCyn4g+sQV4pUgmp9NzSMwmXAzJt3GK9 5 | -----END PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/custom/ec256-private-v2.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MHcCAQEEIFZpgytOAXPVreqGsHPdD9pojw30bnlqfUAqFZ3V3/qeoAoGCCqGSM49 3 | AwEHoUQDQgAE7JbAf3pWEEPje6NG+4dGOwIZnNwRFIe7DnQ4xFWKPrL5tVWlBh7N 4 | DFhjGNhiyO+aQjbcx9uWV74ifq7i21Bemg== 5 | -----END EC PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/custom/ec256-public-v2.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7JbAf3pWEEPje6NG+4dGOwIZnNwR 3 | FIe7DnQ4xFWKPrL5tVWlBh7NDFhjGNhiyO+aQjbcx9uWV74ifq7i21Bemg== 4 | -----END PUBLIC KEY----- 5 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/custom/ec256k-private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MHQCAQEEIMTine3s8tT+8bswDM4/z8o+wIYGb9PQPrw8x6Nu6QDdoAcGBSuBBAAK 3 | oUQDQgAEy8wuv6+fXodLPLfhxm132y1R8m4dkng7tHe7N+sULV2Eth6AxEXQfd+E 4 | 4nuceR21UNCvQKqxiYwCzVwIKcHe/A== 5 | -----END EC PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/custom/ec256k-public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEy8wuv6+fXodLPLfhxm132y1R8m4dkng7 3 | tHe7N+sULV2Eth6AxEXQfd+E4nuceR21UNCvQKqxiYwCzVwIKcHe/A== 4 | -----END PUBLIC KEY----- 5 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/custom/ec512-private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MIHcAgEBBEIB0/+ffxEj7j62xvGaB5pvzk888e412ESO/EK/K0QlS9dSF8+Rj1rG 3 | zqpRB8fvDnoe8xdmkW/W5GKzojMyv7YQYumgBwYFK4EEACOhgYkDgYYABAEw74Yw 4 | aTbPY6TtWmxx6LJDzCX2nKWCPnKdZcEH9Ncu8g5RjRBRq2yacja3OoS6nA2YeDng 5 | reBJxZr376P6Ns6XcQFWDA6K/MCTrEBCsPxXZNxd8KR9vMGWhgNtWRrcKzwJfQkr 6 | suyehZkbbYyFnAWyARKHZuV7VUXmeEmRS/f93MPqVA== 7 | -----END EC PRIVATE KEY----- 8 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/custom/ec512-public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQBMO+GMGk2z2Ok7VpsceiyQ8wl9pyl 3 | gj5ynWXBB/TXLvIOUY0QUatsmnI2tzqEupwNmHg54K3gScWa9++j+jbOl3EBVgwO 4 | ivzAk6xAQrD8V2TcXfCkfbzBloYDbVka3Cs8CX0JK7LsnoWZG22MhZwFsgESh2bl 5 | e1VF5nhJkUv3/dzD6lQ= 6 | -----END PUBLIC KEY----- 7 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/custom/rsa-2048-private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEA4GzZTLU48c4WbyvHi+QKrB71x+T0eq5hqDbQqnlYjhD1Ika7 3 | io1iplsdJWJuyxfYbUkb2Ol0fj4koZ/GS6lgCZr4+8UHbr1qf0Eu5HZSpszs2YxY 4 | 8U5RHnrpw67co7hlgAR9HbyNf5XIYgLV9ldHH/eazwnc3F/hgNsV0xjScVilejgo 5 | cJ4zcsyymvW8t42lteM7bI867ZuJhGop/V+Y0HFyrMsPoQyLuCUpr6ulOfrkr7ZO 6 | dhAIG8r1HcjOp/AUjM15vfXcbUZjkM/VloifX1YitU3upMGJ8/DpFGffMOImrn5r 7 | 6BT494V8rRyN2qvQoAkLJpqZ0avLxwiR2lgVQQIDAQABAoIBAEH0Ozgr2fxWEInD 8 | V/VooypKPvjr9F1JejGxSkmPN9MocKIOH3dsbZ1uEXa3ItBUxan4XlK06SNgp+tH 9 | xULfF/Y6sQlsse59hBq50Uoa69dRShn1AP6JgZVvkduMPBNxUYL5zrs6emsQXb9Q 10 | DglDRQfEAJ7vyxSIqQDxYcyT8uSUF70dqFe+E9B2VE3D6ccHc98k41pJrAFAUFH1 11 | wwvDhfyYr7/Ultut9wzpZvU1meF3Vna3GOUHfxrG6wu1G+WIWHGjouzThsc1qiVI 12 | BtMCJxuCt5fOXRbU4STbMqhB6sZHiOh6J/dZU6JwRYt+IS8FB6kCNFSEWZWQledJ 13 | XqtYSQECgYEA9nmnFTRj3fTBq9zMXfCRujkSy6X2bOb39ftNXzHFuc+I6xmv/3Bs 14 | P9tDdjueP/SnCb7i/9hXkpEIcxjrjiqgcvD2ym1hE4q+odMzRAXYMdnmzI34SVZE 15 | U5hYJcYsXNKrTTleba7QgqdORmyJ9FwqLO40udvmrZMY223XDwgRkOkCgYEA6RkO 16 | 5wjjrWWp/G1YN3KXZTS1m2/eGrUThohXKAfAjbWWiouNLW2msXrxEWsPRL6xKiHu 17 | X9cwZwzi3MstAgk+bphUGUVUkGKNDjWHJA25tDYjbPtkd6xbL4eCHsKpNL3HNYr9 18 | N0CIvgn7qjaHRBem0iK7T6keY4axaSVddEwYapkCgYEA13K5qaB1F4Smcpt8DTWH 19 | vPe8xUUaZlFzOJLmLCsuwmB2N8Ppg2j7RspcaxJsH021YaB5ftjWm+ipMSr8ZPY/ 20 | 8JlPsNzxuYpTXtNmAbT2KYVm6THEch61dTk6/DIBf1YrpUJbl5by7vJeStL/uBmE 21 | SGgksL5XIyzs0opuLdaIvFkCgYAyBLWE8AxjFfCvAQuwAj/ocLITo6KmWnrRIIqL 22 | RXaVMgUWv7FQsTnW1cnK8g05tC2yG8vZ9wQk6Mf5lwOWb0NdWgSZ0528ydj41pWk 23 | L+nMeN2LMjqxz2NVxJ8wWJcUgTCxFZ0WcRumo9/D+6V1ABpE9zz4cBLcSnfhVypB 24 | nV6T6QKBgQCSZNCQ9HPxjAgYcsqc5sjNwuN1GHQZSav3Tye3k6zHENe1lsteT9K8 25 | xciGIuhybKZBvB4yImIIHCtnH+AS+mHAGqHarjNDMfvjOq0dMibPx4+bkIiHdBIH 26 | Xz+j5kmntvFiUnzr0Z/Tcqo+r8FvyCo1YWgwqGP8XoFrswD7gy7cZw== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/custom/rsa-2048-public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4GzZTLU48c4WbyvHi+QK 3 | rB71x+T0eq5hqDbQqnlYjhD1Ika7io1iplsdJWJuyxfYbUkb2Ol0fj4koZ/GS6lg 4 | CZr4+8UHbr1qf0Eu5HZSpszs2YxY8U5RHnrpw67co7hlgAR9HbyNf5XIYgLV9ldH 5 | H/eazwnc3F/hgNsV0xjScVilejgocJ4zcsyymvW8t42lteM7bI867ZuJhGop/V+Y 6 | 0HFyrMsPoQyLuCUpr6ulOfrkr7ZOdhAIG8r1HcjOp/AUjM15vfXcbUZjkM/Vloif 7 | X1YitU3upMGJ8/DpFGffMOImrn5r6BT494V8rRyN2qvQoAkLJpqZ0avLxwiR2lgV 8 | QQIDAQAB 9 | -----END PUBLIC KEY----- 10 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/dsa1024: -------------------------------------------------------------------------------- 1 | -----BEGIN DSA PRIVATE KEY----- 2 | MIIBugIBAAKBgQCH9aAoXvWWThIjkA6D+nI1F9ksF9iDq594rkiGNOT9sPDOdB+n 3 | D+qeeeeloRlj19ymCSADPI0ZLRgkchkAEnY2RnqnhHOjVf/roGgRbW+iQDMbQ9wa 4 | /pvc6/fAbsu1goE1hBYjm98/sZEeXavj8tR56IXnjF1b6Nx0+sgeUKFKEQIVAMiz 5 | 4BJUFeTtddyM4uadBM7HKLPRAoGAZdLBSYNGiij7vAjesF5mGUKTIgPd+JKuBEDx 6 | OaBclsgfdoyoF/TMOkIty+PVlYD+//Vl2xnoUEIRaMXHwHfm0r2xUX++oeRaSScg 7 | YizJdUxe5jvBuBszGPRc/mGpb9YvP0sB+FL1KmuxYmdODfCe51zl8uM/CVhouJ3w 8 | DjmRGscCgYAuFlfC7p+e8huCKydfcv/beftqjewiOPpQ3u5uI6KPCtCJPpDhs3+4 9 | IihH2cPsAlqwGF4tlibW1+/z/OZ1AZinPK3y7b2jSJASEaPeEltVzB92hcd1khk2 10 | jTYcmSsV4VddplOPK9czytR/GbbibxsrhhgZUbd8LPbvIgaiadJ1PgIUBnJ/5vN2 11 | CVArsEzlPUCbohPvZnE= 12 | -----END DSA PRIVATE KEY----- 13 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/dsa256: -------------------------------------------------------------------------------- 1 | -----BEGIN DSA PRIVATE KEY----- 2 | MIH3AgEAAkEAhk2libbY2a8y2Pt21+YPYGZeW6wzaW2yfj5oiClXro9XMR7XWLkE 3 | 9B7XxLNFCS2gmCCdMsMW1HulaHtLFQmB2wIVAM43JZrcgpu6ajZ01VkLc93gu/Ed 4 | AkAOhujZrrKV5CzBKutKLb0GVyVWmdC7InoNSMZEeGU72rT96IjM59YzoqmD0pGM 5 | 3I1o4cGqg1D1DfM1rQlnN1eSAkBq6xXfEDwJ1mLNxF6q8Zm/ugFYWR5xcX/3wFiT 6 | b4+EjHP/DbNh9Vm5wcfnDBJ1zKvrMEf2xqngYdrV/3CiGJeKAhRvL57QvJZcQGvn 7 | ISNX5cMzFHRW3Q== 8 | -----END DSA PRIVATE KEY----- -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/dsa512: -------------------------------------------------------------------------------- 1 | -----BEGIN DSA PRIVATE KEY----- 2 | MIH4AgEAAkEA5lB4GvEwjrsMlGDqGsxrbqeFRh6o9OWt6FgTYiEEHaOYhkIxv0Ok 3 | RZPDNwOG997mDjBnvDJ1i56OmS3MbTnovwIVAJgub/aDrSDB4DZGH7UyarcaGy6D 4 | AkB9HdFw/3td8K4l1FZHv7TCZeJ3ZLb7dF3TWoGUP003RCqoji3/lHdKoVdTQNuR 5 | S/m6DlCwhjRjiQ/lBRgCLCcaAkEAjN891JBjzpMj4bWgsACmMggFf57DS0Ti+5++ 6 | Q1VB8qkJN7rA7/2HrCR3gTsWNb1YhAsnFsoeRscC+LxXoXi9OAIUBG98h4tilg6S 7 | 55jreJD3Se3slps= 8 | -----END DSA PRIVATE KEY----- 9 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/p256: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MHcCAQEEIID49FDqcf1O1eO8saTgG70UbXQw9Fqwseliit2aWhH1oAoGCCqGSM49 3 | AwEHoUQDQgAEFglk2c+oVUIKQ64eZG9bhLNPWB7lSZ/ArK41eGy5wAzU/0G51Xtt 4 | CeBUl+MahZtn9fO1JKdF4qJmS39dXnpENg== 5 | -----END EC PRIVATE KEY----- 6 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/rsa1024: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXgIBAAKBgQDLwsSw1ECnPtT+PkOgHhcGA71nwC2/nL85VBGnRqDxOqjVh7Cx 3 | aKPERYHsk4BPCkE3brtThPWc9kjHEQQ7uf9Y1rbCz0layNqHyywQEVLFmp1cpIt/ 4 | Q3geLv8ZD9pihowKJDyMDiN6ArYUmZczvW4976MU3+l54E6lF/JfFEU5hwIDAQAB 5 | AoGBAKSl/MQarye1yOysqX6P8fDFQt68VvtXkNmlSiKOGuzyho0M+UVSFcs6k1L0 6 | maDE25AMZUiGzuWHyaU55d7RXDgeskDMakD1v6ZejYtxJkSXbETOTLDwUWTn618T 7 | gnb17tU1jktUtU67xK/08i/XodlgnQhs6VoHTuCh3Hu77O6RAkEA7+gxqBuZR572 8 | 74/akiW/SuXm0SXPEviyO1MuSRwtI87B02D0qgV8D1UHRm4AhMnJ8MCs1809kMQE 9 | JiQUCrp9mQJBANlt2ngBO14us6NnhuAseFDTBzCHXwUUu1YKHpMMmxpnGqaldGgX 10 | sOZB3lgJsT9VlGf3YGYdkLTNVbogQKlKpB8CQQDiSwkb4vyQfDe8/NpU5Not0fII 11 | 8jsDUCb+opWUTMmfbxWRR3FBNu8wnym/m19N4fFj8LqYzHX4KY0oVPu6qvJxAkEA 12 | wa5snNekFcqONLIE4G5cosrIrb74sqL8GbGb+KuTAprzj5z1K8Bm0UW9lTjVDjDi 13 | qRYgZfZSL+x1P/54+xTFSwJAY1FxA/N3QPCXCjPh5YqFxAMQs2VVYTfg+t0MEcJD 14 | dPMQD5JX6g5HKnHFg2mZtoXQrWmJSn7p8GJK8yNTopEErA== 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /src/test/ruby/fixtures/pkey/rsa2048: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEAuV9ht9J7k4NBs38jOXvvTKY9gW8nLICSno5EETR1cuF7i4pN 3 | s9I1QJGAFAX0BEO4KbzXmuOvfCpD3CU+Slp1enenfzq/t/e/1IRW0wkJUJUFQign 4 | 4CtrkJL+P07yx18UjyPlBXb81ApEmAB5mrJVSrWmqbjs07JbuS4QQGGXLc+Su96D 5 | kYKmSNVjBiLxVVSpyZfAY3hD37d60uG+X8xdW5v68JkRFIhdGlb6JL8fllf/A/bl 6 | NwdJOhVr9mESHhwGjwfSeTDPfd8ZLE027E5lyAVX9KZYcU00mOX+fdxOSnGqS/8J 7 | DRh0EPHDL15RcJjV2J6vZjPb0rOYGDoMcH+94wIDAQABAoIBAAzsamqfYQAqwXTb 8 | I0CJtGg6msUgU7HVkOM+9d3hM2L791oGHV6xBAdpXW2H8LgvZHJ8eOeSghR8+dgq 9 | PIqAffo4x1Oma+FOg3A0fb0evyiACyrOk+EcBdbBeLo/LcvahBtqnDfiUMQTpy6V 10 | seSoFCwuN91TSCeGIsDpRjbG1vxZgtx+uI+oH5+ytqJOmfCksRDCkMglGkzyfcl0 11 | Xc5CUhIJ0my53xijEUQl19rtWdMnNnnkdbG8PT3LZlOta5Do86BElzUYka0C6dUc 12 | VsBDQ0Nup0P6rEQgy7tephHoRlUGTYamsajGJaAo1F3IQVIrRSuagi7+YpSpCqsW 13 | wORqorkCgYEA7RdX6MDVrbw7LePnhyuaqTiMK+055/R1TqhB1JvvxJ1CXk2rDL6G 14 | 0TLHQ7oGofd5LYiemg4ZVtWdJe43BPZlVgT6lvL/iGo8JnrncB9Da6L7nrq/+Rvj 15 | XGjf1qODCK+LmreZWEsaLPURIoR/Ewwxb9J2zd0CaMjeTwafJo1CZvcCgYEAyCgb 16 | aqoWvUecX8VvARfuA593Lsi50t4MEArnOXXcd1RnXoZWhbx5rgO8/ATKfXr0BK/n 17 | h2GF9PfKzHFm/4V6e82OL7gu/kLy2u9bXN74vOvWFL5NOrOKPM7Kg+9I131kNYOw 18 | Ivnr/VtHE5s0dY7JChYWE1F3vArrOw3T00a4CXUCgYEA0SqY+dS2LvIzW4cHCe9k 19 | IQqsT0yYm5TFsUEr4sA3xcPfe4cV8sZb9k/QEGYb1+SWWZ+AHPV3UW5fl8kTbSNb 20 | v4ng8i8rVVQ0ANbJO9e5CUrepein2MPL0AkOATR8M7t7dGGpvYV0cFk8ZrFx0oId 21 | U0PgYDotF/iueBWlbsOM430CgYEAqYI95dFyPI5/AiSkY5queeb8+mQH62sdcCCr 22 | vd/w/CZA/K5sbAo4SoTj8dLk4evU6HtIa0DOP63y071eaxvRpTNqLUOgmLh+D6gS 23 | Cc7TfLuFrD+WDBatBd5jZ+SoHccVrLR/4L8jeodo5FPW05A+9gnKXEXsTxY4LOUC 24 | 9bS4e1kCgYAqVXZh63JsMwoaxCYmQ66eJojKa47VNrOeIZDZvd2BPVf30glBOT41 25 | gBoDG3WMPZoQj9pb7uMcrnvs4APj2FIhMU8U15LcPAj59cD6S6rWnAxO8NFK7HQG 26 | 4Jxg3JNNf8ErQoCHb1B3oVdXJkmbJkARoDpBKmTCgKtP8ADYLmVPQw== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /src/test/ruby/oaep/encrypted.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXAIBAAKBgQDo6m+QZvYQ/xL0ElLgupK1QDcYL4f5PckwsNgS9pUvV7fzTqCH 3 | k8ThLxTk42MQ2McJsOeUJVP728KhymjFCqxgP4VuwRk9rpAl0+mhy6MPdyjyA6G1 4 | 4jrDWS65ysLchK4t/vwpEDz0SQlEoG1kMzllSm7zZS3XregA7DjNaUYQqwIDAQAB 5 | AoGBALGR6bRBit+yV5TUU3MZSrf8WQSLWDLgs/33FQSAEYSib4+DJke2lKbI6jkG 6 | UoSJgFUXFbaQLtMY2+3VDsMKPBdAge9gIdvbkC4yoKjLGm/FBDOxxZcfLpR+9OPq 7 | U3qM9D0CNuliBWI7Je+p/zs09HIYucpDXy9E18KA1KNF6rfhAkEA9KoNam6wAKnm 8 | vMzz31ws3RuIOUeo2rx6aaVY95+P9tTxd6U+pNkwxy1aCGP+InVSwlYNA1aQ4Axi 9 | /GdMIWMkxwJBAPO1CP7cQNZQmu7yusY+GUObDII5YK9WLaY4RAicn5378crPBFxv 10 | Ukqf9G6FHo7u88iTCIp+vwa3Hn9Tumg3iP0CQQDgUXWBasCVqzCxU5wY4tMDWjXY 11 | hpoLCpmVeRML3dDJt004rFm2HKe7Rhpw7PTZNQZOxUSjFeA4e0LaNf838UWLAkB8 12 | QfbHM3ffjhOg96PhhjINdVWoZCb230LBOHj/xxPfUmFTHcBEfQIBSJMxcrBFAnLL 13 | 9qPpMXymqOFk3ETz9DTlAj8E0qGbp78aVbTOtuwEwNJII+RPw+Zkc+lKR+yaWkAz 14 | fIXw527NPHH3+rnBG72wyZr9ud4LAum9jh+5No1LQpk= 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /src/test/ruby/oaep/test_oaep.rb: -------------------------------------------------------------------------------- 1 | # coding: US-ASCII 2 | require File.expand_path('../test_helper', File.dirname(__FILE__)) 3 | 4 | class TestOaep < TestCase 5 | 6 | def setup 7 | super 8 | 9 | require 'base64' 10 | end 11 | 12 | def test_oaep_decrypt 13 | key = File::read(File.join(File.dirname(__FILE__), 'encrypted.key')) 14 | base64_cipher_text = "s+ydnGyGfJlH6FPB21tYeAeeMKcqLuybw7lxArZIEGRjMNSn2LHNzUEwX/H6FQan5lKQPZxxU1tBuFP6sP27ektEIXgoIQm+PdxilJnNPVoDA9Wff93MMa9JG3VMsc0kbUNMmJf6SQcJ+IB3OyBPZfPrz6wbkwM2zVm9Y/oqFWM=" 15 | 16 | # create cleaned up key object 17 | key = OpenSSL::PKey::RSA.new(key) 18 | 19 | cipher_text = Base64.decode64(base64_cipher_text) 20 | # assert_nothing_raised { 21 | key.private_decrypt(cipher_text, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING) 22 | # } 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /src/test/ruby/pkcs5/test_pbkdf2.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../test_helper', File.dirname(__FILE__)) 2 | 3 | class TestPKCS5 < TestCase 4 | 5 | def test_pbkdf2_hmac_sha1 6 | pass = 'secret' 7 | salt = 'sugar0' 8 | iter = 42 9 | keylen = 24 10 | expected = "\a\xB6I\xE1)\xD8\xA6\x84\xC8D\b\xB2h(]\xBA\x87\xDE\e\xFC\x7F\e\xC3\x06" 11 | expected.force_encoding('ASCII-8BIT') if ''.respond_to?(:force_encoding) 12 | assert_equal expected, OpenSSL::PKCS5.pbkdf2_hmac_sha1(pass, salt, iter, keylen) 13 | end 14 | 15 | def test_pbkdf2_hmac_sha1_with_empty_salt 16 | pass = ' ' 17 | expected = "\x81\e\xE9F\xD8op\xA6\x9D\xF4=\tX\x13\x82D\xF7\xF3\x7F\xC8aFR+" 18 | expected.force_encoding('ASCII-8BIT') if ''.respond_to?(:force_encoding) 19 | assert_equal expected, OpenSSL::PKCS5.pbkdf2_hmac_sha1(pass, '', 16, 24) 20 | end 21 | 22 | def test_pbkdf2_hmac 23 | pass = 'SecreT2' 24 | salt = '0123456789001234567890' 25 | 26 | digest = OpenSSL::Digest::MD5.new 27 | expected = "\xC10D2\x8F\xEA}\xF7ag\xB5\xC8Ad\xFBN9Ff\x9D}\xA6\a\x86\x8F\xC4&HI\x85\x89U" 28 | expected.force_encoding('ASCII-8BIT') if ''.respond_to?(:force_encoding) 29 | assert_equal expected, OpenSSL::PKCS5.pbkdf2_hmac(pass, salt, 120, 48, digest) 30 | assert_equal expected, OpenSSL::PKCS5.pbkdf2_hmac(pass, salt, 120, 48, digest) 31 | 32 | digest = OpenSSL::Digest::SHA256.new 33 | expected = "}\xF4\xE3\xBF\xA7u\xB3[l\xE0(\x84\x96W\xFA\x00h\xA1l#\xB8\xC0Ptirz\v\xBA\x0Es\n<\xF8\xB5(\x85\xDA\xFE\x02y\x14\xB5A`\x8F\xA3\x03\x95\xA7G\xB4pU\xB6pf=Q\x1Fz\x12u\x83" 34 | expected.force_encoding('ASCII-8BIT') if ''.respond_to?(:force_encoding) 35 | assert_equal expected, OpenSSL::PKCS5.pbkdf2_hmac(pass, salt, 100, 64, digest) 36 | 37 | expected = "\x03\x1C\x86\xC7N?\xC3\xBC\xF30W\xEC\x9B\x89I\x8D\xE6|\xA1Y\xEF\bt\xB4\x17\xA9\x87\xCB\xEA\x7F\x92\xDB\x88N@\xCB\x17\xDF\xC4\x8F\xE48L\x1Dy<\xD8\x9B\x8Cx\x85\x93\n\xA3`\xE9]\x90\xA2\x10I[\xE9\x84" 38 | expected.force_encoding('ASCII-8BIT') if ''.respond_to?(:force_encoding) 39 | assert_equal expected, OpenSSL::PKCS5.pbkdf2_hmac(pass, salt, 100, 64, 'SHA512') 40 | end 41 | 42 | 43 | def test_pbkdf2_hmac_sha1_rfc6070_c_4096_len_16 44 | p ="pass\0word" 45 | s = "sa\0lt" 46 | c = 4096 47 | len = 16 48 | raw = %w{ 56 fa 6a a7 55 48 09 9d cc 37 d7 f0 34 25 e0 c3 } 49 | expected = [raw.join('')].pack('H*') 50 | value = OpenSSL::KDF.pbkdf2_hmac(p, salt: s, iterations: c, length: len, hash: 'sha1') 51 | assert_equal(expected, value) 52 | end 53 | 54 | def test_pbkdf2_hmac_sha256_c_20000_len_32 55 | p ="password" 56 | s = OpenSSL::Random.random_bytes(16) 57 | c = 20000 58 | len = 32 59 | digest = OpenSSL::Digest::SHA256.new 60 | value1 = OpenSSL::PKCS5.pbkdf2_hmac(p, s, c, len, digest) 61 | value2 = OpenSSL::KDF.pbkdf2_hmac(p, salt: s, iterations: c, length: len, hash: digest) 62 | assert_equal(value1, value2) 63 | end 64 | 65 | end -------------------------------------------------------------------------------- /src/test/ruby/pkcs7/pkcs7_mime_enveloped.message: -------------------------------------------------------------------------------- 1 | MIME-Version: 1.0 2 | Message-Id: <00103112005203.00349@amyemily.ig.com> 3 | Date: Tue, 31 Oct 2000 12:00:52 -0600 (Central Standard Time) 4 | From: User1 5 | To: User2 6 | Subject: Example 5.3 7 | Content-Type: application/pkcs7-mime; 8 | name=smime.p7m; 9 | smime-type=enveloped-data 10 | Content-Transfer-Encoding: base64 11 | Content-Disposition: attachment; filename=smime.p7m 12 | 13 | 14 | MIIBHgYJKoZIhvcNAQcDoIIBDzCCAQsCAQAxgcAwgb0CAQAwJjASMRAwDgYDVQQDEwdDYXJ 15 | sUlNBAhBGNGvHgABWvBHTbi7NXXHQMA0GCSqGSIb3DQEBAQUABIGAC3EN5nGIiJi2lsGPcP 16 | 2iJ97a4e8kbKQz36zg6Z2i0yx6zYC4mZ7mX7FBs3IWg+f6KgCLx3M1eCbWx8+MDFbbpXadC 17 | DgO8/nUkUNYeNxJtuzubGgzoyEd8Ch4H/dd9gdzTd+taTEgS0ipdSJuNnkVY4/M652jKKHR 18 | LFf02hosdR8wQwYJKoZIhvcNAQcBMBQGCCqGSIb3DQMHBAgtaMXpRwZRNYAgDsiSf8Z9P43 19 | LrY4OxUk660cu1lXeCSFOSOpOJ7FuVyU= 20 | -------------------------------------------------------------------------------- /src/test/ruby/pkcs7/pkcs7_mime_signed.message: -------------------------------------------------------------------------------- 1 | MIME-Version: 1.0 2 | To: User2@examples.com 3 | From: aliceDss@examples.com 4 | Subject: Example 4.9 5 | Message-Id: <021031164540300.304@examples.com> 6 | Date: Thu, 31 Oct 2002 16:45:14 -0300 7 | Content-Type: application/pkcs7-mime; smime-type=signed-data; 8 | name=smime.p7m 9 | Content-Transfer-Encoding: base64 10 | Content-Disposition: attachment; filename=smime.p7m 11 | 12 | 13 | MIIDmQYJKoZIhvcNAQcCoIIDijCCA4YCAQExCTAHBgUrDgMCGjAtBgkqhkiG9w0BBwGgIAQ 14 | eDQpUaGlzIGlzIHNvbWUgc2FtcGxlIGNvbnRlbnQuoIIC4DCCAtwwggKboAMCAQICAgDIMA 15 | kGByqGSM44BAMwEjEQMA4GA1UEAxMHQ2FybERTUzAeFw05OTA4MTcwMTEwNDlaFw0zOTEyM 16 | zEyMzU5NTlaMBMxETAPBgNVBAMTCEFsaWNlRFNTMIIBtjCCASsGByqGSM44BAEwggEeAoGB 17 | AIGNze2D6gqeOT7CSCij5EeT3Q7XqA7sU8WrhAhP/5Thc0h+DNbzREjR/p+vpKGJL+HZMMg 18 | 23j+bv7dM3F9piuR10DcMkQiVm96nXvn89J8v3UOoi1TxP7AHCEdNXYjDw7Wz41UIddU5dh 19 | DEeL3/nbCElzfy5FEbteQJllzzflvbAhUA4kemGkVmuBPG2o+4NyErYov3k80CgYAmONAUi 20 | TKqOfs+bdlLWWpMdiM5BAI1XPLLGjDDHlBd3ZtZ4s2qBT1YwHuiNrhuB699ikIlp/R1z0oI 21 | Xks+kPht6pzJIYo7dhTpzi5dowfNI4W4LzABfG1JiRGJNkS9+MiVSlNWteL5c+waYTYfEX/ 22 | Cve3RUP+YdMLRgUpgObo2OQOBhAACgYBc47ladRSWC6l63eM/qeysXty9txMRNKYWiSgRI9 23 | k0hmd1dRMSPUNbb+VRv/qJ8qIbPiR9PQeNW2PIu0WloErjhdbOBoA/6CN+GvIkq1MauCcNH 24 | u8Iv2YUgFxirGX6FYvxuzTU0pY39mFHssQyhPB+QUD9RqdjTjPypeL08oPluKOBgTB/MAwG 25 | A1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgbAMB8GA1UdIwQYMBaAFHBEPoIub4feStN14z0 26 | gvEMrk/EfMB0GA1UdDgQWBBS+bKGz48H37UNwpM4TAeL945f+zTAfBgNVHREEGDAWgRRBbG 27 | ljZURTU0BleGFtcGxlLmNvbTAJBgcqhkjOOAQDAzAAMC0CFFUMpBkfQiuJcSIzjYNqtT1na 28 | 79FAhUAn2FTUlQLXLLd2ud2HeIQUltDXr0xYzBhAgEBMBgwEjEQMA4GA1UEAxMHQ2FybERT 29 | UwICAMgwBwYFKw4DAhowCQYHKoZIzjgEAwQuMCwCFD1cSW6LIUFzeXle3YI5SKSBer/sAhQ 30 | mCq7s/CTFHOEjgASeUjbMpx5g6A== 31 | -------------------------------------------------------------------------------- /src/test/ruby/pkcs7/pkcs7_multipart_signed.message: -------------------------------------------------------------------------------- 1 | MIME-Version: 1.0 2 | To: User2@examples.com 3 | From: aliceDss@examples.com 4 | Subject: Example 4.8 5 | Message-Id: <020906002550300.249@examples.com> 6 | Date: Fri, 06 Sep 2002 00:25:21 -0300 7 | Content-Type: multipart/signed; 8 | micalg=SHA1; 9 | boundary="----=_NextBoundry____Fri,_06_Sep_2002_00:25:21"; 10 | protocol="application/pkcs7-signature" 11 | 12 | 13 | This is a multi-part message in MIME format. 14 | 15 | 16 | ------=_NextBoundry____Fri,_06_Sep_2002_00:25:21 17 | 18 | This is some sample content. 19 | 20 | ------=_NextBoundry____Fri,_06_Sep_2002_00:25:21 21 | Content-Type: application/pkcs7-mime; name=smime.p7s 22 | Content-Transfer-Encoding: base64 23 | Content-Disposition: attachment; filename=smime.p7s 24 | 25 | 26 | MIIDdwYJKoZIhvcNAQcCoIIDaDCCA2QCAQExCTAHBgUrDgMCGjALBgkqhkiG9w0BBwGgggL 27 | gMIIC3DCCApugAwIBAgICAMgwCQYHKoZIzjgEAzASMRAwDgYDVQQDEwdDYXJsRFNTMB4XDT 28 | k5MDgxNzAxMTA0OVoXDTM5MTIzMTIzNTk1OVowEzERMA8GA1UEAxMIQWxpY2VEU1MwggG2M 29 | IIBKwYHKoZIzjgEATCCAR4CgYEAgY3N7YPqCp45PsJIKKPkR5PdDteoDuxTxauECE//lOFz 30 | SH4M1vNESNH+n6+koYkv4dkwyDbeP5u/t0zcX2mK5HXQNwyRCJWb3qde+fz0ny/dQ6iLVPE 31 | /sAcIR01diMPDtbPjVQh11Tl2EMR4vf+dsISXN/LkURu15AmWXPN+W9sCFQDiR6YaRWa4E8 32 | baj7g3IStii/eTzQKBgCY40BSJMqo5+z5t2UtZakx2IzkEAjVc8ssaMMMeUF3dm1nizaoFP 33 | VjAe6I2uG4Hr32KQiWn9HXPSgheSz6Q+G3qnMkhijt2FOnOLl2jB80jhbgvMAF8bUmJEYk2 34 | RL34yJVKU1a14vlz7BphNh8Rf8K97dFQ/5h0wtGBSmA5ujY5A4GEAAKBgFzjuVp1FJYLqXr 35 | d4z+p7Kxe3L23ExE0phaJKBEj2TSGZ3V1ExI9Q1tv5VG/+onyohs+JH09B41bY8i7RaWgSu 36 | OF1s4GgD/oI34a8iSrUxq4Jw0e7wi/ZhSAXGKsZfoVi/G7NNTSljf2YUeyxDKE8H5BQP1Gp 37 | 2NOM/Kl4vTyg+W4o4GBMH8wDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBsAwHwYDVR0j 38 | BBgwFoAUcEQ+gi5vh95K03XjPSC8QyuT8R8wHQYDVR0OBBYEFL5sobPjwfftQ3CkzhMB4v3 39 | jl/7NMB8GA1UdEQQYMBaBFEFsaWNlRFNTQGV4YW1wbGUuY29tMAkGByqGSM44BAMDMAAwLQ 40 | IUVQykGR9CK4lxIjONg2q1PWdrv0UCFQCfYVNSVAtcst3a53Yd4hBSW0NevTFjMGECAQEwG 41 | DASMRAwDgYDVQQDEwdDYXJsRFNTAgIAyDAHBgUrDgMCGjAJBgcqhkjOOAQDBC4wLAIUM/mG 42 | f6gkgp9Z0XtRdGimJeB/BxUCFGFFJqwYRt1WYcIOQoGiaowqGzVI 43 | 44 | 45 | ------=_NextBoundry____Fri,_06_Sep_2002_00:25:21-- 46 | -------------------------------------------------------------------------------- /src/test/ruby/pkcs7/test_attribute.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../test_helper', File.dirname(__FILE__)) 2 | 3 | module PKCS7Test 4 | class TestAttribute < TestCase 5 | 6 | def test_attributes 7 | val = org.bouncycastle.asn1.DEROctetString.new("foo".to_java_bytes) 8 | val2 = org.bouncycastle.asn1.DEROctetString.new("bar".to_java_bytes) 9 | attr = org.jruby.ext.openssl.impl.Attribute.create(123, 444, val) 10 | assert_raise NoMethodError do 11 | attr.type = 12 12 | end 13 | assert_raise NoMethodError do 14 | attr.value = val2 15 | end 16 | 17 | assert_equal 123, attr.type 18 | assert_equal val, attr.set.get(0) 19 | 20 | attr2 = org.jruby.ext.openssl.impl.Attribute.create(123, 444, val) 21 | 22 | assert_equal attr, attr2 23 | 24 | assert_not_equal org.jruby.ext.openssl.impl.Attribute.create(124, 444, val), attr 25 | assert_not_equal org.jruby.ext.openssl.impl.Attribute.create(123, 444, val2), attr 26 | end 27 | 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /src/test/ruby/pkcs7/test_bio.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../test_helper', File.dirname(__FILE__)) 2 | 3 | module PKCS7Test 4 | class TestBIO < TestCase 5 | 6 | def test_string_bio_simple 7 | bio = org.jruby.ext.openssl.impl.BIO::from_string("abc") 8 | arr = Java::byte[20].new 9 | read = bio.gets(arr, 10) 10 | assert_equal 3, read 11 | assert_equal "abc".to_java_bytes.to_a, arr.to_a[0...read] 12 | end 13 | 14 | def test_string_bio_simple_with_newline 15 | bio = org.jruby.ext.openssl.impl.BIO::from_string("abc\n") 16 | arr = Java::byte[20].new 17 | read = bio.gets(arr, 10) 18 | assert_equal 4, read 19 | assert_equal "abc\n".to_java_bytes.to_a, arr.to_a[0...read] 20 | end 21 | 22 | def test_string_bio_simple_with_newline_and_more_data 23 | bio = org.jruby.ext.openssl.impl.BIO::from_string("abc\nfoo\n\nbar") 24 | arr = Java::byte[20].new 25 | read = bio.gets(arr, 10) 26 | assert_equal 4, read 27 | assert_equal "abc\n".to_java_bytes.to_a, arr.to_a[0...read] 28 | 29 | read = bio.gets(arr, 10) 30 | assert_equal 4, read 31 | assert_equal "foo\n".to_java_bytes.to_a, arr.to_a[0...read] 32 | 33 | read = bio.gets(arr, 10) 34 | assert_equal 1, read 35 | assert_equal "\n".to_java_bytes.to_a, arr.to_a[0...read] 36 | 37 | read = bio.gets(arr, 10) 38 | assert_equal 3, read 39 | assert_equal "bar".to_java_bytes.to_a, arr.to_a[0...read] 40 | 41 | read = bio.gets(arr, 10) 42 | assert_equal 0, read 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /src/test/ruby/pkcs7_helper.rb: -------------------------------------------------------------------------------- 1 | module PKCS7Test 2 | 3 | MimeEnvelopedString = File::read(File.join(File.dirname(__FILE__), 'pkcs7', 'pkcs7_mime_enveloped.message')) 4 | MimeSignedString = File::read(File.join(File.dirname(__FILE__), 'pkcs7', 'pkcs7_mime_signed.message')) 5 | MultipartSignedString = File::read(File.join(File.dirname(__FILE__), 'pkcs7', 'pkcs7_multipart_signed.message')) 6 | 7 | X509CertString = <= 0 23 | 24 | session.timeout = 5 25 | assert_equal 5, session.timeout 26 | 27 | assert session == OpenSSL::SSL::Session.new(ssl) 28 | 29 | ssl.close 30 | end 31 | end 32 | 33 | def test_alpn_protocol_selection_ary 34 | advertised = ["h2", "http/1.1"] 35 | ctx_proc = Proc.new { |ctx| 36 | ctx.alpn_select_cb = -> (protocols) { 37 | assert_equal Array, protocols.class 38 | assert_equal advertised, protocols 39 | protocols.first 40 | } 41 | } 42 | start_server0(PORT, OpenSSL::SSL::VERIFY_NONE, true, ctx_proc: ctx_proc) do |server, port| 43 | sock = TCPSocket.new("127.0.0.1", port) 44 | ctx = OpenSSL::SSL::SSLContext.new("TLSv1_2") 45 | ctx.alpn_protocols = advertised 46 | ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx) 47 | ssl.sync_close = true 48 | ssl.connect 49 | assert_equal("h2", ssl.alpn_protocol) 50 | ssl.puts "abc"; assert_equal "abc\n", ssl.gets 51 | end 52 | end 53 | 54 | def test_exposes_session_error 55 | OpenSSL::SSL::Session::SessionError 56 | end 57 | 58 | end -------------------------------------------------------------------------------- /src/test/ruby/test_hmac.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('test_helper', File.dirname(__FILE__)) 2 | 3 | class TestHMAC < TestCase 4 | 5 | def setup 6 | super 7 | 8 | @digest = OpenSSL::Digest::MD5 9 | @key = "KEY" 10 | @data = "DATA" 11 | @h1 = OpenSSL::HMAC.new(@key, @digest.new) 12 | @h2 = OpenSSL::HMAC.new(@key, "MD5") 13 | end 14 | 15 | def test_to_s 16 | @h1.update(''); @h1.update('1234567890') 17 | assert_equal(@h1.hexdigest, @h1.to_s) 18 | assert_equal(@h2.hexdigest, @h2.to_s) 19 | end 20 | 21 | def test_reset 22 | data = 'He is my neighbor Nursultan Tuliagby. He is pain in my assholes.' 23 | @h1.update('4'); @h1.update('2') 24 | @h1.reset 25 | @h1.update(data) 26 | @h2.update(data) 27 | assert_equal(@h2.digest, @h1.digest) 28 | end 29 | 30 | def test_correct_digest 31 | assert_equal('c17c7b655b11574fea8d676a1fdc0ca8', @h2.hexdigest) # calculated on MRI 32 | @h2.update('DATA') 33 | assert_equal('9e50596c0fa1197f8587443a942d8afc', @h2.hexdigest) # calculated on MRI 34 | @h2.reset 35 | @h2.update("\xFF") # invalid utf-8 char 36 | assert_equal('0770623462e782b51bb0689a8ba4f3f1', @h2.hexdigest) # calcualted on MRI 37 | end 38 | 39 | def test_hexdigest_with_empty_key 40 | result = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('md5'), "", "foo") 41 | assert_equal "4acb10ca3965a14a080297db0921950c", result 42 | end 43 | 44 | end 45 | -------------------------------------------------------------------------------- /src/test/ruby/test_openssl.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('test_helper', File.dirname(__FILE__)) 2 | 3 | require 'openssl' 4 | 5 | class TestOpenSSL < TestCase 6 | 7 | # only test this when the gem is installed - i.e. during integration tests 8 | def test_gem_version 9 | assert_equal ENV['BC_VERSION'], Java::OrgBouncycastleJceProvider::BouncyCastleProvider.new.info.sub( /[^0-9.]*/, '' ) 10 | # we have a jruby-openssl gem loaded 11 | assert Gem.loaded_specs[ 'jruby-openssl' ] != nil 12 | assert Gem.loaded_specs[ 'jruby-openssl' ].full_gem_path.match( /!/ ) == nil 13 | end if ENV['BC_VERSION'] 14 | 15 | def test_version 16 | assert_equal String, OpenSSL::VERSION.class 17 | assert /\d\.\d\.\d/ =~ OpenSSL::VERSION, OpenSSL::VERSION 18 | 19 | assert OpenSSL::OPENSSL_VERSION.index('OpenSSL') 20 | if defined? JRUBY_VERSION 21 | assert_equal 0, OpenSSL::OPENSSL_VERSION.index('JRuby-OpenSSL ') 22 | end 23 | assert OpenSSL::OPENSSL_VERSION_NUMBER 24 | 25 | # MRI 2.3 openssl/utils.rb does this (and we shall pass) : 26 | assert defined?(OpenSSL::OPENSSL_LIBRARY_VERSION) 27 | assert /\AOpenSSL +0\./ !~ OpenSSL::OPENSSL_LIBRARY_VERSION 28 | end 29 | 30 | # some gems check this - better to be conservative until 3.0.0 APIs are fully supported 31 | def test_version_lt_3_0_0 32 | assert OpenSSL::OPENSSL_VERSION_NUMBER < 3 * 0x10000000 33 | end 34 | 35 | def test_debug 36 | debug = OpenSSL.debug 37 | assert (OpenSSL.debug == true || OpenSSL.debug == false) 38 | assert OpenSSL.debug= true 39 | assert_equal true, OpenSSL.debug 40 | ensure 41 | OpenSSL.debug = debug 42 | end 43 | 44 | def test_stubs 45 | OpenSSL.deprecated_warning_flag 46 | OpenSSL.check_func(:func, :header) 47 | OpenSSL.fips_mode = false 48 | assert !OpenSSL.fips_mode 49 | end 50 | 51 | def test_Digest 52 | digest = OpenSSL.Digest('MD5') 53 | assert_equal OpenSSL::Digest::MD5, digest 54 | end 55 | 56 | end # unless defined? OpenSSL::OPENSSL_DUMMY 57 | 58 | 59 | class TestOpenSSLStub < TestCase 60 | 61 | def test_autoload_consts_error 62 | assert_raise(LoadError) { OpenSSL::ASN1 } 63 | assert_raise(LoadError) { OpenSSL::BN } 64 | assert_raise(LoadError) { OpenSSL::Cipher } 65 | assert_raise(LoadError) { OpenSSL::Config } 66 | assert_raise(LoadError) { OpenSSL::Netscape } 67 | assert_raise(LoadError) { OpenSSL::PKCS7 } 68 | assert_raise(LoadError) { OpenSSL::PKey } 69 | assert_raise(LoadError) { OpenSSL::Random } 70 | assert_raise(LoadError) { OpenSSL::SSL } 71 | assert_raise(LoadError) { OpenSSL::X509 } 72 | end 73 | 74 | end if defined? OpenSSL::OPENSSL_DUMMY 75 | # This test only makes sense if the gem isn't installed -------------------------------------------------------------------------------- /src/test/ruby/test_random.rb: -------------------------------------------------------------------------------- 1 | # coding: US-ASCII 2 | require File.expand_path('test_helper', File.dirname(__FILE__)) 3 | 4 | class TestRandom < TestCase 5 | 6 | def test_api 7 | assert_equal 24, OpenSSL::Random.random_bytes(24).size 8 | assert_equal 1024, OpenSSL::Random.random_bytes(1024).size 9 | 10 | OpenSSL::Random.seed OpenSSL::Random.random_bytes(24) 11 | assert_equal 42, OpenSSL::Random.random_bytes(42).size 12 | 13 | assert_equal true, OpenSSL::Random.status? 14 | 15 | assert_equal 24, OpenSSL::Random.pseudo_bytes(24).size 16 | assert_equal 1024, OpenSSL::Random.pseudo_bytes(1024).size 17 | end 18 | 19 | def test_stubs 20 | OpenSSL::Random.random_add('42', :entropy) 21 | OpenSSL::Random.egd('hello.rb') 22 | OpenSSL::Random.egd_bytes('hello.rb', 42) 23 | end 24 | 25 | end -------------------------------------------------------------------------------- /src/test/ruby/test_security_helper.rb: -------------------------------------------------------------------------------- 1 | # coding: US-ASCII 2 | require File.expand_path('test_helper', File.dirname(__FILE__)) 3 | 4 | class TestSecurityHelper < TestCase 5 | 6 | def setup; require 'openssl'; require 'java' 7 | super 8 | end 9 | 10 | def test_cert_factory_provider_leak # GH-94 11 | assert provider = org.jruby.ext.openssl.SecurityHelper.getSecurityProvider 12 | assert_equal 'BC', provider.name 13 | factory1 = org.jruby.ext.openssl.SecurityHelper.getCertificateFactory('X.509') 14 | factory2 = org.jruby.ext.openssl.SecurityHelper.getCertificateFactory('X.509') 15 | assert_not_same factory1, factory2 16 | assert_equal 'BC', factory1.provider.name 17 | assert_equal 'BC', factory2.provider.name 18 | # assert_same factory1.getProvider, factory2.getProvider 19 | 20 | begin 21 | java.security.cert.CertificateFactory.class_eval do 22 | field_reader :certFacSpi 23 | end 24 | 25 | spi1 = factory1.certFacSpi; spi2 = factory2.certFacSpi 26 | rescue SecurityError => e 27 | return skip "#{__method__} probably needs --add-opens (#{e.message})" 28 | end 29 | 30 | if spi1.is_a? org.bouncycastle.jcajce.provider.asymmetric.x509.CertificateFactory 31 | org.bouncycastle.jcajce.provider.asymmetric.x509.CertificateFactory.class_eval do 32 | field_reader :bcHelper 33 | end 34 | if (spi1.bcHelper rescue nil) 35 | org.bouncycastle.jcajce.util.ProviderJcaJceHelper.class_eval do 36 | field_reader :provider rescue nil 37 | end 38 | if spi1.bcHelper.respond_to?(:provider) 39 | assert_same spi1.bcHelper.provider, spi2.bcHelper.provider 40 | end 41 | end 42 | end 43 | end if defined? JRUBY_VERSION 44 | 45 | end -------------------------------------------------------------------------------- /src/test/ruby/x509/Entrust.net_Premium_2048_Secure_Server_CA.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEKjCCAxKgAwIBAgIEOGPe+DANBgkqhkiG9w0BAQUFADCBtDEUMBIGA1UEChML 3 | RW50cnVzdC5uZXQxQDA+BgNVBAsUN3d3dy5lbnRydXN0Lm5ldC9DUFNfMjA0OCBp 4 | bmNvcnAuIGJ5IHJlZi4gKGxpbWl0cyBsaWFiLikxJTAjBgNVBAsTHChjKSAxOTk5 5 | IEVudHJ1c3QubmV0IExpbWl0ZWQxMzAxBgNVBAMTKkVudHJ1c3QubmV0IENlcnRp 6 | ZmljYXRpb24gQXV0aG9yaXR5ICgyMDQ4KTAeFw05OTEyMjQxNzUwNTFaFw0yOTA3 7 | MjQxNDE1MTJaMIG0MRQwEgYDVQQKEwtFbnRydXN0Lm5ldDFAMD4GA1UECxQ3d3d3 8 | LmVudHJ1c3QubmV0L0NQU18yMDQ4IGluY29ycC4gYnkgcmVmLiAobGltaXRzIGxp 9 | YWIuKTElMCMGA1UECxMcKGMpIDE5OTkgRW50cnVzdC5uZXQgTGltaXRlZDEzMDEG 10 | A1UEAxMqRW50cnVzdC5uZXQgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgKDIwNDgp 11 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArU1LqRKGsuqjIAcVFmQq 12 | K0vRvwtKTY7tgHalZ7d4QMBzQshowNtTK91euHaYNZOLGp18EzoOH1u3Hs/lJBQe 13 | sYGpjX24zGtLA/ECDNyrpUAkAH90lKGdCCmziAv1h3edVc3kw37XamSrhRSGlVuX 14 | MlBvPci6Zgzj/L24ScF2iUkZ/cCovYmjZy/Gn7xxGWC4LeksyZB2ZnuU4q941mVT 15 | XTzWnLLPKQP5L6RQstRIzgUyVYr9smRMDuSYB3Xbf9+5CFVghTAp+XtIpGmG4zU/ 16 | HoZdenoVve8AjhUiVBcAkCaTvA5JaJG/+EfTnZVCwQ5N328mz8MYIWJmQ3DW1cAH 17 | 4QIDAQABo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNV 18 | HQ4EFgQUVeSB0RGAvtiJuQijMfmhJAkWuXAwDQYJKoZIhvcNAQEFBQADggEBADub 19 | j1abMOdTmXx6eadNl9cZlZD7Bh/KM3xGY4+WZiT6QBshJ8rmcnPyT/4xmf3IDExo 20 | U8aAghOY+rat2l098c5u9hURlIIM7j+VrxGrD9cv3h8Dj1csHsm7mhpElesYT6Yf 21 | zX1XEC+bBAlahLVu2B064dae0Wx5XnkcFMXj0EyTO2U87d89vqbllRrDtRnDvV5b 22 | u/8j72gZyxKTJ1wDLW8w0B62GqzeWvfRqqgnpv55gcR5mTNXuhKwqeBCbJPKVt7+ 23 | bYQLCIt+jerXmCHG8+c8eS9enNFMFY3h7CI3zJpDC5fcgJCNs2ebb0gIFVbPv/Er 24 | fF6adulZkMV8gzURZVE= 25 | -----END CERTIFICATE----- 26 | -------------------------------------------------------------------------------- /src/test/ruby/x509/Entrust.net_Secure_Server_CA.expired.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIE2DCCBEGgAwIBAgIEN0rSQzANBgkqhkiG9w0BAQUFADCBwzELMAkGA1UEBhMC 3 | VVMxFDASBgNVBAoTC0VudHJ1c3QubmV0MTswOQYDVQQLEzJ3d3cuZW50cnVzdC5u 4 | ZXQvQ1BTIGluY29ycC4gYnkgcmVmLiAobGltaXRzIGxpYWIuKTElMCMGA1UECxMc 5 | KGMpIDE5OTkgRW50cnVzdC5uZXQgTGltaXRlZDE6MDgGA1UEAxMxRW50cnVzdC5u 6 | ZXQgU2VjdXJlIFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05OTA1 7 | MjUxNjA5NDBaFw0xOTA1MjUxNjM5NDBaMIHDMQswCQYDVQQGEwJVUzEUMBIGA1UE 8 | ChMLRW50cnVzdC5uZXQxOzA5BgNVBAsTMnd3dy5lbnRydXN0Lm5ldC9DUFMgaW5j 9 | b3JwLiBieSByZWYuIChsaW1pdHMgbGlhYi4pMSUwIwYDVQQLExwoYykgMTk5OSBF 10 | bnRydXN0Lm5ldCBMaW1pdGVkMTowOAYDVQQDEzFFbnRydXN0Lm5ldCBTZWN1cmUg 11 | U2VydmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGdMA0GCSqGSIb3DQEBAQUA 12 | A4GLADCBhwKBgQDNKIM0VBuJ8w+vN5Ex/68xYMmo6LIQaO2f55M28Qpku0f1BBc/ 13 | I0dNxScZgSYMVHINiC3ZH5oSn7yzcdOAGT9HZnuMNSjSuQrfJNqc1lB5gXpa0zf3 14 | wkrYKZImZNHkmGw6AIr1NJtl+O3jEP/9uElY3KDegjlrgbEWGWG5VLbmQwIBA6OC 15 | AdcwggHTMBEGCWCGSAGG+EIBAQQEAwIABzCCARkGA1UdHwSCARAwggEMMIHeoIHb 16 | oIHYpIHVMIHSMQswCQYDVQQGEwJVUzEUMBIGA1UEChMLRW50cnVzdC5uZXQxOzA5 17 | BgNVBAsTMnd3dy5lbnRydXN0Lm5ldC9DUFMgaW5jb3JwLiBieSByZWYuIChsaW1p 18 | dHMgbGlhYi4pMSUwIwYDVQQLExwoYykgMTk5OSBFbnRydXN0Lm5ldCBMaW1pdGVk 19 | MTowOAYDVQQDEzFFbnRydXN0Lm5ldCBTZWN1cmUgU2VydmVyIENlcnRpZmljYXRp 20 | b24gQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMCmgJ6AlhiNodHRwOi8vd3d3LmVu 21 | dHJ1c3QubmV0L0NSTC9uZXQxLmNybDArBgNVHRAEJDAigA8xOTk5MDUyNTE2MDk0 22 | MFqBDzIwMTkwNTI1MTYwOTQwWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAU8Bdi 23 | E1U9s/8KAGv7UISX8+1i0BowHQYDVR0OBBYEFPAXYhNVPbP/CgBr+1CEl/PtYtAa 24 | MAwGA1UdEwQFMAMBAf8wGQYJKoZIhvZ9B0EABAwwChsEVjQuMAMCBJAwDQYJKoZI 25 | hvcNAQEFBQADgYEAkNwwAvpkdMKnCqV8IY00F6j7Rw7/JXyNEwr75Ji174z4xRAN 26 | 95K+8cPV1ZVqBLssziY2ZcgxxufuP+NXdYR6Ee9GTxj005i7qIcyunL2POI9n9cd 27 | 2cNgQ4xYDiKWL2KjLB+6rQXvqzJ4h6BUcxm1XAX5Uj5tLUUL9wqT6u0G+bI= 28 | -----END CERTIFICATE----- 29 | -------------------------------------------------------------------------------- /src/test/ruby/x509/SETUP.txt: -------------------------------------------------------------------------------- 1 | $ /usr/lib/ssl/misc/CA.sh -newca 2 | 3 | $ /usr/lib/ssl/misc/CA.sh -newreq 4 | 5 | $ /usr/lib/ssl/misc/CA.sh -sign 6 | Signed certificate is in newcert.pem 7 | 8 | $ keytool -importcert --file demoCA/cacert.pem -alias demoCA -keystore javastore.ts -storetype jks -storepass keystore 9 | Trust this certificate? [no]: y 10 | Certificate was added to keystore 11 | 12 | $ keytool -list -keystore javastore.ts 13 | Enter keystore password: 14 | Keystore type: JKS 15 | Keystore provider: SUN 16 | 17 | Your keystore contains 1 entry 18 | 19 | democa, Apr 20, 2024, trustedCertEntry, 20 | Certificate fingerprint (SHA-256): ... 21 | -------------------------------------------------------------------------------- /src/test/ruby/x509/demoCA/careq.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICnDCCAYQCAQAwVzELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUx 3 | ITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEQMA4GA1UEAwwHZGVt 4 | by5jYTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKCLuuyy4vxHuajd 5 | WalHSTcKsGHF7u5zvPatmszy49mChqep71udLrlCGMZGAbk9FQyJe8J6vBfeVENK 6 | iVVToc98W3rSx0X+2trTpsUkVddpi4Xb0b9HQ0W7tHRIUJGZgYS11jXUZsbQabR7 7 | jvhH9PdHqKUBh0DUQVdOkxMKQSIULePcrABwLdHPCCjZe2TT3UitznVXkD+dw9OM 8 | 04BElk5xcXzb99EfOgktE0zexxlcwbbLypH41n4iMqrUUV1pat80gZmM/Q4iMBeJ 9 | IBX/tQCpSarz1WXlyJ2/x4/6f1Z34F20hqbXcNb2dov+iIQrKyiBJ1lFCDs5UtDf 10 | AJ24VMcCAwEAAaAAMA0GCSqGSIb3DQEBCwUAA4IBAQCTcwtA28eCbhgz9xraP8UL 11 | VVdlLXzXUJVIg1ekjLyp7blSyNRx4c/Eymw03QTZOJqG3J9h9NbQ1fpsGcRpiruh 12 | qHI7gM+givDP+IjPIuz3kOToZtmJ3Nj25fKmBpGcy0ftcoJ9ZpwYcVzlgA4eT07v 13 | XHhYX64b9EAJttKGB3sFfI1ecTaeZ9sRpAuIYm6jtfcsH/oEfFPVAs/FfHGcCy3B 14 | aqvBOUfFbxqPPe+aDRYKnTcaKvtZIbg61IqRUpW2o+tBCnr/RJMV21jBaEIGnT2B 15 | TLdwMZ2xniFRjIr9UEGNR0lC0HAufGAZBqRy4NPUT9128mz5kYnftafXC5Y5J7UB 16 | -----END CERTIFICATE REQUEST----- 17 | -------------------------------------------------------------------------------- /src/test/ruby/x509/demoCA/index.txt: -------------------------------------------------------------------------------- 1 | V 270420110921Z 7FE0E82756779BDA39DFF3AEE16916DE984FFD24 unknown /C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=demo.ca 2 | V 250420111357Z 7FE0E82756779BDA39DFF3AEE16916DE984FFD25 unknown /C=AU/ST=None/O=JRuby Dev Team/OU=JOSSL/CN=jruby.org 3 | -------------------------------------------------------------------------------- /src/test/ruby/x509/demoCA/index.txt.attr: -------------------------------------------------------------------------------- 1 | unique_subject = yes 2 | -------------------------------------------------------------------------------- /src/test/ruby/x509/demoCA/index.txt.attr.old: -------------------------------------------------------------------------------- 1 | unique_subject = yes 2 | -------------------------------------------------------------------------------- /src/test/ruby/x509/demoCA/index.txt.old: -------------------------------------------------------------------------------- 1 | V 270420110921Z 7FE0E82756779BDA39DFF3AEE16916DE984FFD24 unknown /C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=demo.ca 2 | -------------------------------------------------------------------------------- /src/test/ruby/x509/demoCA/private/cakey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN ENCRYPTED PRIVATE KEY----- 2 | MIIFHDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQIga/rK91RImECAggA 3 | MAwGCCqGSIb3DQIJBQAwFAYIKoZIhvcNAwcECKwVl8kx/xDEBIIEyJlHqU2PSAWV 4 | vHlaaYalchpBH2aZ88In3JcFuQ8t+sTr8AmTL2PBg/KVEyiDLeCcWbAJcvpkM6y2 5 | GJjAxAYiibipVwbG0Zx/7YJqq3FdG64Bo+z8yI4AFk+lTTU9Kvezz20y+N7+qZuX 6 | JBQu8yJsbMw7MMmsk1Ydt/nmu1gF/sX3r8eJ4ELi7cUPu9juBffXTtsE7nXJTeZL 7 | j+7Ubh6YhF1JHmEz5b+6x16KZ971FHUkb7VS7BP9gK84LWfVSoLPOTRP66zIT8Ob 8 | fi3EgRKjqE99YZFIkKWJx+zv0nmJz25dZMdXdTGZgVS7pfTavPHkdbAyqeEXa+RE 9 | 63RpPa4aW5rge54enfIl+EIxG6Xds9jn4oZJP4V8kHsmfx2JAziBnXp5Z5wBJXjk 10 | NekM78sP3AnHVwtPbsmUP2r5IVA+l3AAYhckaCw8V65TrQZu86CWiUoOj5pDuJub 11 | v65/+rrYYcrDdJTvrh86Ws0e1AjNZvV7TW2sgA+J29cuM1WigGFwV2iYsvvmU+EY 12 | PoXSX10PRdg73k6NeJ75/653mbATp/35LPY1N7zGYmQap0Y8llErp+7m7au6LHsX 13 | zxqp6PISAGXtJTQBngBBf0wgMYZlErzNXpcVglea9Xa8dw163sMKJ3F8dEB6gK9M 14 | Gm7KRK1gM0wUbrA0i0fOasHmqTZKYJLWYcVaoqc9qQAdSuU9USWgriJl1rHe0g7q 15 | PT/jbSKLFn6e5cYlcIy7lfXQRoReh6fT7HnN7noej3IGZ7+2u1iOQTVYo/RvHXOt 16 | EcRS5AhycWoVa4p/hGsAdLm1/P5jJL96MgZUpwH1Wp/PkaZptn4fhAzsmLnthsSn 17 | ArMl7+PLu3Sv/ojfPAWeuoZvCTe3imPoL/k3sMPseGeRUKuq8QzCNLrBTwCeagtF 18 | kH3/JqZim8kmlvum+stCt2CusnfQX4PFF7aLjiZzr0mAouScQTJXNKDdYGzEIOhL 19 | 5iZ+RvzUAh42VVVj0BkDMbrWmr+FV4MFqF+Tw2EQB6jVQyVupRQfTIRvDy3DPKX7 20 | fLWNwOzVUCCIjJxPWCT8DmTpAmIVb6SsZ3uSh3LkKjMxKSAe6n0r/gkD65o/N1p1 21 | f5d+vCrUHp/BdHRV1L+8sYrHE0j8Df5xTVSgnbQkPFXqBU3WiwqfRY4eN7ZDGvS+ 22 | /SSd1FLnLrieXEDfz9dVScbCrqAVD7IfRvvrE+IOV0/WnuV7gLN/ARYT0RF05JJd 23 | KFqbT48exw4nV8RGGQHdQTdtQYiaSz5Pj+jqHX6xvjI7wxyeDpuQQK0FcBHzbHVg 24 | fplulR0TAZzhh1cMk1KeKAugAelBhE6LYGViWa6oHLAYIygghE3sR3ey9CXMfjr8 25 | 4M3eqZNnPODqt9fY40DEaxPRXsspSExfpWycRrl8pEMRtwi330E7mZ5Z2LYVtiNu 26 | PYYi7LK+xa6MsftdSn/MsmumNMQqNIiu6ZDZ2iuRdHM1aBzdV8CJ66CSn3NvkYjt 27 | zQj6kZweVFsRufcLinwUSO3s+w+6O0bmQTLbFsE7w9+cxHnrHuQxZXKrX2DIxgSU 28 | CN1sGp+t/HZpguIegBvAdL6U3WTtZkYqOJgdPU7J6XDj2P5M6RW3RWiTsWhjbveU 29 | AuJKvhA0WgNS4+XnyBwZNw== 30 | -----END ENCRYPTED PRIVATE KEY----- 31 | -------------------------------------------------------------------------------- /src/test/ruby/x509/demoCA/private/cakey.pem.passwd: -------------------------------------------------------------------------------- 1 | cakey 2 | -------------------------------------------------------------------------------- /src/test/ruby/x509/demoCA/serial: -------------------------------------------------------------------------------- 1 | 7FE0E82756779BDA39DFF3AEE16916DE984FFD26 2 | -------------------------------------------------------------------------------- /src/test/ruby/x509/demoCA/serial.old: -------------------------------------------------------------------------------- 1 | 7FE0E82756779BDA39DFF3AEE16916DE984FFD25 2 | -------------------------------------------------------------------------------- /src/test/ruby/x509/digicert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEtjCCA56gAwIBAgIQDHmpRLCMEZUgkmFf4msdgzANBgkqhkiG9w0BAQsFADBs 3 | MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 4 | d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j 5 | ZSBFViBSb290IENBMB4XDTEzMTAyMjEyMDAwMFoXDTI4MTAyMjEyMDAwMFowdTEL 6 | MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3 7 | LmRpZ2ljZXJ0LmNvbTE0MDIGA1UEAxMrRGlnaUNlcnQgU0hBMiBFeHRlbmRlZCBW 8 | YWxpZGF0aW9uIFNlcnZlciBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC 9 | ggEBANdTpARR+JmmFkhLZyeqk0nQOe0MsLAAh/FnKIaFjI5j2ryxQDji0/XspQUY 10 | uD0+xZkXMuwYjPrxDKZkIYXLBxA0sFKIKx9om9KxjxKws9LniB8f7zh3VFNfgHk/ 11 | LhqqqB5LKw2rt2O5Nbd9FLxZS99RStKh4gzikIKHaq7q12TWmFXo/a8aUGxUvBHy 12 | /Urynbt/DvTVvo4WiRJV2MBxNO723C3sxIclho3YIeSwTQyJ3DkmF93215SF2AQh 13 | cJ1vb/9cuhnhRctWVyh+HA1BV6q3uCe7seT6Ku8hI3UarS2bhjWMnHe1c63YlC3k 14 | 8wyd7sFOYn4XwHGeLN7x+RAoGTMCAwEAAaOCAUkwggFFMBIGA1UdEwEB/wQIMAYB 15 | Af8CAQAwDgYDVR0PAQH/BAQDAgGGMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEF 16 | BQcDAjA0BggrBgEFBQcBAQQoMCYwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmRp 17 | Z2ljZXJ0LmNvbTBLBgNVHR8ERDBCMECgPqA8hjpodHRwOi8vY3JsNC5kaWdpY2Vy 18 | dC5jb20vRGlnaUNlcnRIaWdoQXNzdXJhbmNlRVZSb290Q0EuY3JsMD0GA1UdIAQ2 19 | MDQwMgYEVR0gADAqMCgGCCsGAQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5j 20 | b20vQ1BTMB0GA1UdDgQWBBQ901Cl1qCt7vNKYApl0yHU+PjWDzAfBgNVHSMEGDAW 21 | gBSxPsNpA/i/RwHUmCYaCALvY2QrwzANBgkqhkiG9w0BAQsFAAOCAQEAnbbQkIbh 22 | hgLtxaDwNBx0wY12zIYKqPBKikLWP8ipTa18CK3mtlC4ohpNiAexKSHc59rGPCHg 23 | 4xFJcKx6HQGkyhE6V6t9VypAdP3THYUYUN9XR3WhfVUgLkc3UHKMf4Ib0mKPLQNa 24 | 2sPIoc4sUqIAY+tzunHISScjl2SFnjgOrWNoPLpSgVh5oywM395t6zHyuqB8bPEs 25 | 1OG9d4Q3A84ytciagRpKkk47RpqF/oOi+Z6Mo8wNXrM9zwR4jxQUezKcxwCmXMS1 26 | oVWNWlZopCJwqjyBcdmdqEU79OX2olHdx3ti6G8MdOu42vi/hw15UJGQmxg7kVkn 27 | 8TUoE6smftX3eg== 28 | -----END CERTIFICATE----- 29 | -------------------------------------------------------------------------------- /src/test/ruby/x509/dsa.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFmjCCBUECCQCyVP+siddScDAJBgcqhkjOOAQDMB4xCzAJBgNVBAYTAkRFMQ8w 3 | DQYDVQQHDAZCZXJsaW4wHhcNMjMwMzAzMTIyODQ2WhcNMjMwNDAyMTIyODQ2WjAe 4 | MQswCQYDVQQGEwJERTEPMA0GA1UEBwwGQmVybGluMIIExzCCAzoGByqGSM44BAEw 5 | ggMtAoIBgQDLKx9elgtAt8cgYcXWPIye512chP+wcJw4hDGjyHbtkdshsI4us/Sg 6 | FruQ8/aCwXDGOHgn/nDJQ5np3/3NiIXcWkBCcGfmbRjc3T2P/Umu3O6JaK9ejvpJ 7 | l7GQkZnQOrDE3VJz9/3hw7BqsbsEc5NW6ruefBwTI4EpEVxZrvKWa9K2eAeRqAGO 8 | u2tosdqoVnl08u/quu2WQ7XIdeY9otmeKdmwGStgFd3TzjfB3d98VcuQbkBfem6g 9 | HT26YyU+sLickWh7FqJkv8Nr9YgFRUEzxuKLa9gKXn1RIz71nPXaIvUfuFQNfnQf 10 | 0rdmZULdXcHRnZFxwkPn6N+46tEhiLtCKEQ+bfx7o/mfd4WlhMAeCtu8pw7kthr0 11 | bLo/ZKlbl6JIV9O3kGd4QeghB1UzH8WbiyV/EZYy84XpJxfDWTeBJLquLE0M/kKa 12 | +kb/QkEWcPptN62WtD3MVZhBhuZLQBcPXrKfgM3522jAWlL6ryK9sC1L4KULBPZ/ 13 | XeIti2dEjD0CIQDjLh4LaF4hfd7BLvj/TRs9Eq+W94ekiIJFuCP1RtR/vwKCAYEA 14 | wqM29Tv5dl0IMKad/sX0Ui8ZqwUfudsSO5a3W8kv9ovxVzrfjjBIq2C8ysrI4bzQ 15 | lfk9fKhlEj7ZEjBkBaDoVfvD9oY1BzQxiCl9nmNQwW6drV+x6A6CnvZh3mNgrnMn 16 | TRUjdJEThjoaG+Z6yN2igEhPBjLrNOeh26CPzFu4r7tbFsjXUT1PDQkCD5yDSZLP 17 | sUWoGJgh9rgw1UWgKn9n6fKALRSbeM1Z4NfmQK65eOrhSitMmgrcSUV/0Cnntcfd 18 | PBYBYuuxzw7tO6exqKTMid7nRo0SjhRb/bCZmlsAnbTHdcYN2/tAyY3jt6aYuTXS 19 | bvzZ5gAPxjeYGLyaTJzXvCaYfAzpbC0Ks2Q2SkZLrxW6unS/pRXFPBtNxDTN+OfS 20 | PB4SErFyo8Xr2Do2CzigG5YLnTe+ELr31W5oY63PetE/OKoNVvSUDjFttt9MoDs7 21 | 5kkzswVx/WsYfYOWll0/iINqteSSctQnQHzPMP2sLe4c3PomMve9bHyIBLDtWKhT 22 | A4IBhQACggGAbjm99bX6Y6gvMrF6QbfNsdXeQLwPWrfeET/3CuWdbM5smPDQXzal 23 | nM0tnZCDwOuLbT7PxDOHuw1oOMv5sYLupjblU8NoDGWzJAVeUKjfftuWptwrbgdh 24 | qkE+vHfmIduHHqHIl+ZMhS/F3C8/u6CctCy5sO/iYuIKzyYE//tZpf+jnVQ4j79m 25 | Sa4skFufzUDVu7CLWd4LYkHzjRXNBAnbjF0/WJKOdnCdYlSwkhPC3VqjBGOBlotb 26 | B8UE0XjKlx7LiSWEWCckLLo7WAU88d5ZXJhhJ4jeY8pYvYyRJ+hqh9sMORRs7I5V 27 | 5K2ysI3QYIbXmhN4gHkl0J84TWQ4ZVkjKfyJYFDtyH8x13GCyaGYwRFVLlkSkxx3 28 | lKASIE3vdc8h5yUXlNjWoPtL9pPc9BqmtkKXEYtYkdDkkL/lYVJ0CV8R5wM+ccx4 29 | M2cyysvDFnRpe1uNlU/joC76In6I7pYQE9UOhVGxjyX2+ZqRXEgn924Rjbksfg7G 30 | AU389kgxJPhDMAkGByqGSM44BAMDSAAwRQIgH1GIKxmcIj27rVD9B2GhTNClelzW 31 | fCFwnp5AEY02RwsCIQDE0V6ITkW9xxaQz8/bjvlCmVTJtJFD9rtZVjWhmrIgqg== 32 | -----END CERTIFICATE----- 33 | -------------------------------------------------------------------------------- /src/test/ruby/x509/ec-ca.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIHcMIGDAgEBMAoGCCqGSM49BAMCMBAxDjAMBgNVBAMTBWVjLWNhFw0yMzA1MDIx 3 | NDIwNTFaGA8yMDczMDIyODE0MjA1MVowGzAZAggXW1l2cygQyxcNMjMwNTAyMTQy 4 | MDUxWqAjMCEwHwYDVR0jBBgwFoAUttNRPFixOdwcEEs8Zc/AP+XGM8IwCgYIKoZI 5 | zj0EAwIDSAAwRQIhAIY/kYfZbkAJUOQkXcJrGfeZLUYpt2mofamD2aHGhaE8AiAh 6 | rW6t9BQ3xUCKHTODJHJHe+otaiwSCXoVI2jlJBcDWg== 7 | -----END X509 CRL----- 8 | -------------------------------------------------------------------------------- /src/test/ruby/x509/ec-ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIBWzCCAQCgAwIBAgIIF1tZdnMbfdcwCgYIKoZIzj0EAwIwEDEOMAwGA1UEAxMF 3 | ZWMtY2EwIBcNMjMwNTAyMTQyMDUxWhgPMjA3MzA0MTkxNDIwNTFaMBAxDjAMBgNV 4 | BAMTBWVjLWNhMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE3xYZYfagw6booMq2 5 | L/4x2RKVgwWM4UbAbycJHuubBESVic8AApX1WcjOEKjQt+9GqVFAJxKzjlxGA+Hc 6 | SVlpIaNCMEAwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0O 7 | BBYEFLbTUTxYsTncHBBLPGXPwD/lxjPCMAoGCCqGSM49BAMCA0kAMEYCIQD5QgDE 8 | 1AijBncz7ItMv+q2vED1/AqNNY/whm71/wGK+QIhANkGiD6DdrydjEgVuFTvW/Kg 9 | S122sk5XXx5zlCmZVZQA 10 | -----END CERTIFICATE----- 11 | -------------------------------------------------------------------------------- /src/test/ruby/x509/ec.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIBLDCB0gIJAJRzFaGbFWl5MAoGCCqGSM49BAMCMB4xCzAJBgNVBAYTAkRFMQ8w 3 | DQYDVQQHDAZCZXJsaW4wHhcNMjMwMzAzMTIxMzU4WhcNMjMwNDAyMTIxMzU4WjAe 4 | MQswCQYDVQQGEwJERTEPMA0GA1UEBwwGQmVybGluMFkwEwYHKoZIzj0CAQYIKoZI 5 | zj0DAQcDQgAEtyX3CxW6sRambalSi0XwFLK4sIV7eJekaOX3hV05oGDl1umT84OL 6 | HHctC4+VcJ5R98gsDA9x8c8jT3o09yqarjAKBggqhkjOPQQDAgNJADBGAiEA9ALb 7 | jJ4w2bQ3QsxdneNYo1T3yUKjpPk4C2/wWpiU354CIQCAtuLX7Fwb2xfGXFzpOgK7 8 | OcwGN+Mb5xA9eR17/uq07Q== 9 | -----END CERTIFICATE----- 10 | -------------------------------------------------------------------------------- /src/test/ruby/x509/gibberish.pem: -------------------------------------------------------------------------------- 1 | something but not any pem section -------------------------------------------------------------------------------- /src/test/ruby/x509/javastore.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jruby-openssl/a2be52f3b69ff82b9dc886e19d77275701d48189/src/test/ruby/x509/javastore.ts -------------------------------------------------------------------------------- /src/test/ruby/x509/newkey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN ENCRYPTED PRIVATE KEY----- 2 | MIIFHDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQIptI6IvNIXLQCAggA 3 | MAwGCCqGSIb3DQIJBQAwFAYIKoZIhvcNAwcECGgu1pMy79jcBIIEyEOSty89/eCt 4 | JNyk3QHvg254W31IfjwiUwHE8WfzXXrQJxAxaFKwsMLZQ1B5E85C1Hvaol1Ufr7E 5 | okC8Erm0UDBF9GsBhKBHclgh97clvqsA1oxdnIwJmn/0W7fZbhI3o3/34iTZvEmy 6 | C5gQ9h4mgpi1RXBKofu2HYp9YFSu+8xz/A75U8k33oCTIcBh8l3XUpf1iczB9KUN 7 | Np1e+HKfSkbyT60GrnOiRGtJXn7X67OHLNIMjB902zccW0ByA0ZTB4tv/Fbvohcw 8 | L3bytY+CixS/DBlvGVX+JT7NxOpRTVBeXpLiv5GG2zi+uL8EFHfzqblM8OW+l5j7 9 | SiJeQ0pCvIeKT3cIgzVIWpO3FNzQ0ucP4AjvFvKOXkyey/aLpmi9cJ9m8uPvJSuN 10 | wNtzfxVXdQ1bgbos2GmFQmriSWSinagKWWm1zsqElNlQue9jOdRK44HosllgGd1Y 11 | GuneH+LFAGEBCefxA3zO00uACPlqhY5HO545YrYkaHGJ6eMtjojb+P8rsNvJ9c4e 12 | 8/IDIzVPo7zDSTuFiZFFGCU3GQSKjOrDfLb+cNdHfqMAjiyEjmeYkdrkxanKFyBv 13 | Tc1Cpi5EicpXHK/Lfu77r64Hg06cItIkgJh8P+m5/X0JU/c2Ynqq8paXs4eqqt7t 14 | q6t1okvy7kOpDEQ/UyLcMqKtPmnJa68bpJDkbTuWXCexFrQhnYyIxuHJtRVKp/oz 15 | mBsUexZpHp8PtCCB4dbyU+AuADZO1GMS8BJWBGh3I4/kDGnZ2C8UpSQ+UfbaOtu/ 16 | hMoNT21jvadogd4by1DeFkYBjIQxwPoSaZfTRkcwu2NozJJlZT0f3MtMlntLJrR9 17 | wMQMviv/uEJGcQUJ4oNMHjkkK2N5pqZ2f8GOLuRm7xuHSAHBKjN9XHshoxjTiOPn 18 | DmplHX+vaRr+J9GAfmkg/jr2u4fGeFp+Y08HPbAfpvlxHuR6HWcDBm0vhK4qt0rx 19 | vBxsZs2hQr6m43eCPgJG92PDD/o831/6IMLsW/kowrDiSBfIVo9LFvPteFilA+Bd 20 | QVUh1CMnxqeWsfswzK38EwcHXxz1dLdL/aH6z7OkdAUzHaFaY8VZnEfECQfdHgJB 21 | Yk2NEuatOsQynTcCenXz0H86gYQT3mftneVWgM2AXDpTEBQ5XeU4iWUbVt0/s3ho 22 | tEYfcNUEacYVaQ9d5M4sylMIPm6Hx/MGx1zddgAw637w8dPWipsQbR860qW1uaZJ 23 | oQrIRIPq/n/W7kkM5XBZmAoLLPjvCzjtF6FGXiW8yrkN0HF1hs/nK50McorbqRYy 24 | MGV+jEHpzTE2CWPyTFjXn2idSJz4nX0D6IgjIbM9zB67cXHwsUMnGpVOMgaqB4en 25 | weaUWRUzau6mPa2o3eM5UHcSbbwXVDtHKIne6pZqpA6XATBPmRQujWA5GqWQ9PyO 26 | 6r2DTrVRh1aYKsXl0EyX0OBPkB6C1ULoY+X4gT8riEX8mZSCn4aM6TYheCdhAHwo 27 | Zya5au7bxE+oimNrMuVDPRuGAizvox/ZCi9NgFbFxUFm8xC62g1mru0FU1y3thmO 28 | sAigENLt0iA15L0miimBnEjUbksIx7Ug0zr2VwpVe3knDo4o4FWBOOUPet6hg+lU 29 | oCkOpwuVQReqT6UE7feIvw== 30 | -----END ENCRYPTED PRIVATE KEY----- 31 | -------------------------------------------------------------------------------- /src/test/ruby/x509/newreq.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICtDCCAZwCAQAwWTELMAkGA1UEBhMCQVUxDTALBgNVBAgMBE5vbmUxFzAVBgNV 3 | BAoMDkpSdWJ5IERldiBUZWFtMQ4wDAYDVQQLDAVKT1NTTDESMBAGA1UEAwwJanJ1 4 | Ynkub3JnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs4Ob+OddJc2s 5 | 3BmqRs7/ZjCwndofJDKxmoL8u9BKOJb+s2RRkqARXFFP89zZKV4l7YsXNWuyAQoQ 6 | zupNZ3+zoRJt3W4xERKnVphKiYfn6E0jqmoobk+0c5sPbecyW1BGDgZdluRbI7Gz 7 | 86SbEv+hfBrvdmqwUr8DGrh8B434UxWA5Tc4BQEB7yXXhuodeQ/8ADUNfU2cn9jW 8 | LkLfchOKSTpZrqfZoaeSdMrBq8VHBK2xP2kCpAnglLuAVIHmirwc29tgh2Z3jfkr 9 | v3S63D1aIPpa/VBLp0Pz4hEEMQpCaR9MbdtxoFsa6HAsaT7pzs5OwYM8OcsrjUVy 10 | Cj24dMj3qQIDAQABoBYwFAYJKoZIhvcNAQkCMQcMBUpSdWJ5MA0GCSqGSIb3DQEB 11 | CwUAA4IBAQCc5UgGQGiJPKbYoBQ/ro0hejCX6rvyTmjpJwJTBX07JtcQmLDpQZkt 12 | kfwPOw/nCQS1q+QcO7gvjyULYCFuAJ+Ff+kyCYEMv4uQ7Xkc6U9sQSzdCSaXp6ob 13 | yR6boc26ioI9FZrwyGxEeu6XGlQ2ihRKjfx0sbdIoHKiSsWk9AZZXT3SgxtcnKDh 14 | zbMx1NAvQ8dO7mn1bWIYi5zfWjTIMGTrxD2GT3GuybWP/VXEJi5Nz9idfeN2dpPq 15 | yJH1mKTJZv/7ZRAF9kQwuDO5gtVuRzR3qSENpjOSmpKEn1hm8o1966APLV6SJZC4 16 | fsyzgvHK5Tsu+I5bj1CLmLjNppvQkaTu 17 | -----END CERTIFICATE REQUEST----- 18 | -------------------------------------------------------------------------------- /src/test/ruby/x509/revoked.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIICATCCAasCAQEwDQYJKoZIhvcNAQEFBQAwYTELMAkGA1UEBhMCVVMxEDAOBgNV 3 | BAgMB0Zsb3JpZGExDjAMBgNVBAcMBU1pYW1pMRwwGgYDVQQKDBNyNTA5LWNlcnQt 4 | dmFsaWRhdG9yMRIwEAYDVQQDDAlsb2NhbGhvc3QXDTE0MDcwNzE3MzEzNVoXDTI0 5 | MDcwNDE4MzEzNVowgeQwJAITBj4XOQip5iM9jsjNahP+ln2bNhcNMTQwMjExMTU0 6 | MjMyWjAkAhMGPhffXa7qnjiOsKG+T59MXoICFw0xNDAyMTExNjE5MjNaMCQCEwY+ 7 | G/iZDaYOYqQNkUhWz2VDQQYXDTE0MDIxMTIwMTE0OVowJAITBj4b+xUAmYEJh7F0 8 | Ek7YjFlzhhcNMTQwMjExMjAxMjIyWjAkAhMGPhv+d3hbmVhej514YzyCQvIOFw0x 9 | NDAyMTEyMDEzMDdaMCQCEwZMlT4VU+7hoQBdGcEGWKf/tEYXDTE0MDcwNzE4MzEz 10 | NVqgLzAtMAoGA1UdFAQDAgEGMB8GA1UdIwQYMBaAFJg2dyTKjan/rPrS2dVd1VDm 11 | 92pRMA0GCSqGSIb3DQEBBQUAA0EASi1yCsP5ZphMI7XsTE65XwB9ABNcP36UHtdV 12 | m9iz/ZQpSeFoTlokJyy6c4+fVVIiDDUbOOAdN0RWmgEqkhLCYA== 13 | -----END X509 CRL----- -------------------------------------------------------------------------------- /src/test/ruby/x509/rsa.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDjzCCAnegAwIBAgIUMbWvdUeWTEuSK5ppK5B6S+7LzO0wDQYJKoZIhvcNAQEL 3 | BQAwVzELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM 4 | GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEQMA4GA1UEAwwHZGVtby5jYTAeFw0y 5 | MDAxMjkxNTQzNTZaFw0yMzAxMjgxNTQzNTZaMFcxCzAJBgNVBAYTAkFVMRMwEQYD 6 | VQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBM 7 | dGQxEDAOBgNVBAMMB2RlbW8uY2EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK 8 | AoIBAQDOenkwnxjXDl7yD3Io23c+t777WOBNT+/XkElOCNCfp8ogbB6JVfZz2MW6 9 | MeNqfemnotsMM12OvnebL3QGHDVFFdsQ9Gnt3LaEttHhC/Xg8FSHk41g0D/guaJc 10 | XVhhgJBTW7hHl/vwCT8H/07z4ItGvILjttKCy89PqzxbodEoYNwNc/VSsQy9Eox/ 11 | y2Z01EuiemcdvTMhZd6u8O5d5d0C52gbLmLeIkVmwOzOO7+9tJhEGcNJFGna4U5e 12 | Phu2Hk8PiI4B4VpvlXMIxpOJQWXrxnhwNRf6SSKWCEZOopH82YUPmILMPAiIubjI 13 | s2y2XwQXtt1Kj16RJriHngOn68gNAgMBAAGjUzBRMB0GA1UdDgQWBBS2JI9T0SRm 14 | 8h3qTzcr8Do6eLpdRTAfBgNVHSMEGDAWgBS2JI9T0SRm8h3qTzcr8Do6eLpdRTAP 15 | BgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAojDNYMlZaZvjr2CQX 16 | OBVSY6ZJjiKkI1c4Ihx1Dx7RqJeGYUnqwrzRU5HTlvAvLUHfFMIV9ahXeuRlpsJ5 17 | DY2kjTwtyTozF8IPPEwc8DQrFhuO2qaZOzvCbYWqO5uqx0TKxXN227xv85pHT2if 18 | 7IwhJwKInQg1d56heZ6Isz0tFysXeY7NJZ3iYgBg7PsBTeDiAPAW3XvXY2naSXui 19 | vp12fnfcH7GF8QrcuCiqrgDfNASsfkONfCDBmOPJdLmxoGHcXxwORrGM2XQkPeAU 20 | c/exZclzK5ke4rWkm0DoC/soHkCPkwE7LFcS0Uzvmyb5ORPSycBVS5mS13cz7YAy 21 | L/wk 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /src/test/ruby/x509/test_x509revoked.rb: -------------------------------------------------------------------------------- 1 | # coding: US-ASCII 2 | require File.expand_path('../test_helper', File.dirname(__FILE__)) 3 | 4 | class TestX509Revoked < TestCase 5 | 6 | def setup; require 'openssl' end 7 | 8 | def test_new 9 | rev = OpenSSL::X509::Revoked.new 10 | assert_equal 0, rev.serial 11 | assert_equal nil, rev.time 12 | assert_equal [], rev.extensions 13 | if RUBY_VERSION >= '2.0.0' || defined? JRUBY_VERSION 14 | assert rev.inspect.index('#