Skip to content

Commit 00b4ebd

Browse files
committed
[fix] OpenSSL::X509::Request#dup behavior
1 parent 5774307 commit 00b4ebd

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/main/java/org/jruby/ext/openssl/X509Request.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.security.PrivateKey;
4141

4242
import org.bouncycastle.asn1.ASN1Encoding;
43+
import org.bouncycastle.asn1.ASN1Sequence;
4344
import org.bouncycastle.asn1.ASN1Set;
4445
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
4546
import org.bouncycastle.asn1.pkcs.Attribute;
@@ -151,13 +152,31 @@ private static IRubyObject newName(final ThreadContext context, X500Name name) {
151152
@Override
152153
@JRubyMethod(visibility = Visibility.PRIVATE)
153154
public IRubyObject initialize_copy(IRubyObject obj) {
154-
final Ruby runtime = getRuntime();
155-
warn(runtime.getCurrentContext(), "WARNING: unimplemented method called: OpenSSL::X509::Request#initialize_copy");
156-
157155
if ( this == obj ) return this;
158156

159157
checkFrozen();
160-
// subject = public_key = null;
158+
159+
final X509Request that = (X509Request) obj;
160+
final ThreadContext context = getRuntime().getCurrentContext();
161+
162+
this.subject = that.subject == null ? null : newName(context, getX500Name(that.subject));
163+
this.public_key = that.public_key == null ? null : (PKey) that.public_key.dup();
164+
this.version = that.version;
165+
166+
this.attributes.clear();
167+
for ( X509Attribute attribute : that.attributes ) {
168+
this.attributes.add( (X509Attribute) attribute.dup() );
169+
}
170+
171+
final PKCS10Request request = that.request;
172+
if ( request != null ) {
173+
final ASN1Sequence requestSequence = request.toASN1Structure();
174+
this.request = requestSequence.size() == 0 ? null : new PKCS10Request(requestSequence);
175+
}
176+
else {
177+
this.request = null;
178+
}
179+
161180
return this;
162181
}
163182

src/test/ruby/x509/test_x509req.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ def test_version
109109
assert_equal 1, req.version
110110
end
111111

112+
def test_dup; setup!
113+
req = issue_csr(0, @dn, @rsa1024, OpenSSL::Digest.new('SHA256'))
114+
assert_equal req.to_der, req.dup.to_der
115+
end
116+
112117
# from GH-150
113118
def test_to_der_new_from_der; require 'base64'
114119
# Build the CSR

0 commit comments

Comments
 (0)