Skip to content

Commit eaeae1c

Browse files
committed
[compat] reject non-Set X509 attribute values
1 parent 75befae commit eaeae1c

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎src/main/java/org/jruby/ext/openssl/X509Attribute.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ public IRubyObject set_value(final ThreadContext context, final IRubyObject valu
189189
//if ( value instanceof ASN1.ASN1Data ) {
190190
// return this.value = value;
191191
//}
192-
return this.value = ASN1.decodeImpl(context, value);
192+
final IRubyObject decoded = ASN1.decodeImpl(context, value);
193+
final RubyClass setClass = _ASN1(context.runtime).getClass("Set");
194+
if (!setClass.isInstance(decoded)) {
195+
throw newAttributeError(context.runtime, "attribute value must be ASN1::Set: nested asn1 error");
196+
}
197+
return this.value = decoded;
193198
}
194199
catch (IOException e) {
195200
throw newIOError(context.runtime, e);
@@ -221,4 +226,9 @@ private static RaiseException newAttributeError(Ruby runtime, Exception cause) {
221226
return RubySupport.newError(runtime, AttributeError, cause.getMessage(), cause);
222227
}
223228

229+
private static RaiseException newAttributeError(Ruby runtime, String message) {
230+
RubyClass AttributeError = _X509(runtime).getClass("AttributeError");
231+
return RubySupport.newError(runtime, AttributeError, message);
232+
}
233+
224234
}// X509Attribute

‎test/x509/test_x509attr.rb‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def test_new_with_oid_and_value
3232
assert_equal val.to_der, attr.value.to_der
3333
end
3434

35+
def test_new_with_non_set_value
36+
error = assert_raise(OpenSSL::X509::AttributeError) do
37+
OpenSSL::X509::Attribute.new("challengePassword", OpenSSL::ASN1::EndOfContent.new)
38+
end
39+
40+
assert_equal "attribute value must be ASN1::Set: nested asn1 error", error.message
41+
end
42+
3543
def test_dup
3644
attr = OpenSSL::X509::Attribute.new(CHALLENGE_PASSWORD_DER)
3745
assert_equal attr.to_der, attr.dup.to_der

0 commit comments

Comments
 (0)