@@ -149,10 +149,14 @@ static const rb_data_type_t ossl_ocsp_certid_type = {
149149 * Public
150150 */
151151static VALUE
152- ossl_ocspcertid_new ( OCSP_CERTID * cid )
152+ ossl_ocspcid_new ( const OCSP_CERTID * cid )
153153{
154154 VALUE obj = NewOCSPCertId (cOCSPCertId );
155- SetOCSPCertId (obj , cid );
155+ /* OpenSSL 1.1.1 takes a non-const pointer */
156+ OCSP_CERTID * cid_new = OCSP_CERTID_dup ((OCSP_CERTID * )cid );
157+ if (!cid_new )
158+ ossl_raise (eOCSPError , "OCSP_CERTID_dup" );
159+ SetOCSPCertId (obj , cid_new );
156160 return obj ;
157161}
158162
@@ -328,21 +332,19 @@ static VALUE
328332ossl_ocspreq_get_certid (VALUE self )
329333{
330334 OCSP_REQUEST * req ;
331- OCSP_ONEREQ * one ;
332- OCSP_CERTID * id ;
333- VALUE ary , tmp ;
334- int i , count ;
335335
336336 GetOCSPReq (self , req );
337- count = OCSP_request_onereq_count (req );
338- ary = (count > 0 ) ? rb_ary_new () : Qnil ;
339- for (i = 0 ; i < count ; i ++ ){
340- one = OCSP_request_onereq_get0 (req , i );
341- tmp = NewOCSPCertId (cOCSPCertId );
342- if (!(id = OCSP_CERTID_dup (OCSP_onereq_get0_id (one ))))
343- ossl_raise (eOCSPError , NULL );
344- SetOCSPCertId (tmp , id );
345- rb_ary_push (ary , tmp );
337+ int count = OCSP_request_onereq_count (req );
338+ if (count < 0 )
339+ ossl_raise (eOCSPError , "OCSP_request_onereq_count" );
340+ if (count == 0 )
341+ return Qnil ;
342+
343+ VALUE ary = rb_ary_new_capa (count );
344+ for (int i = 0 ; i < count ; i ++ ) {
345+ OCSP_ONEREQ * one = OCSP_request_onereq_get0 (req , i );
346+ OCSP_CERTID * cid = OCSP_onereq_get0_id (one );
347+ rb_ary_push (ary , ossl_ocspcid_new (cid ));
346348 }
347349
348350 return ary ;
@@ -899,48 +901,40 @@ static VALUE
899901ossl_ocspbres_get_status (VALUE self )
900902{
901903 OCSP_BASICRESP * bs ;
902- OCSP_SINGLERESP * single ;
903- OCSP_CERTID * cid ;
904- ASN1_TIME * revtime , * thisupd , * nextupd ;
905- int status , reason ;
906- X509_EXTENSION * x509ext ;
907- VALUE ret , ary , ext ;
908- int count , ext_count , i , j ;
909904
910905 GetOCSPBasicRes (self , bs );
911- ret = rb_ary_new ();
912- count = OCSP_resp_count (bs );
913- for (i = 0 ; i < count ; i ++ ){
914- single = OCSP_resp_get0 (bs , i );
915- if (!single ) continue ;
916-
917- revtime = thisupd = nextupd = NULL ;
918- status = OCSP_single_get0_status (single , & reason , & revtime ,
919- & thisupd , & nextupd );
920- if (status < 0 ) continue ;
921- if (!(cid = OCSP_CERTID_dup ((OCSP_CERTID * )OCSP_SINGLERESP_get0_id (single )))) /* FIXME */
922- ossl_raise (eOCSPError , NULL );
923- ary = rb_ary_new ();
924- rb_ary_push (ary , ossl_ocspcertid_new (cid ));
925- rb_ary_push (ary , INT2NUM (status ));
926- rb_ary_push (ary , INT2NUM (reason ));
927- rb_ary_push (ary , revtime ? asn1time_to_time (revtime ) : Qnil );
928- rb_ary_push (ary , thisupd ? asn1time_to_time (thisupd ) : Qnil );
929- rb_ary_push (ary , nextupd ? asn1time_to_time (nextupd ) : Qnil );
930- ext = rb_ary_new ();
931- ext_count = OCSP_SINGLERESP_get_ext_count (single );
932- for (j = 0 ; j < ext_count ; j ++ ){
933- x509ext = OCSP_SINGLERESP_get_ext (single , j );
934- rb_ary_push (ext , ossl_x509ext_new (x509ext ));
935- }
936- rb_ary_push (ary , ext );
937- rb_ary_push (ret , ary );
906+ VALUE ret = rb_ary_new ();
907+ int count = OCSP_resp_count (bs );
908+ for (int i = 0 ; i < count ; i ++ ) {
909+ OCSP_SINGLERESP * single = OCSP_resp_get0 (bs , i );
910+ ASN1_TIME * revtime , * thisupd , * nextupd ;
911+ int reason ;
912+
913+ int status = OCSP_single_get0_status (single , & reason , & revtime , & thisupd , & nextupd );
914+ if (status < 0 )
915+ ossl_raise (eOCSPError , "OCSP_single_get0_status" );
916+
917+ VALUE ary = rb_ary_new ();
918+ rb_ary_push (ary , ossl_ocspcid_new (OCSP_SINGLERESP_get0_id (single )));
919+ rb_ary_push (ary , INT2NUM (status ));
920+ rb_ary_push (ary , INT2NUM (reason ));
921+ rb_ary_push (ary , revtime ? asn1time_to_time (revtime ) : Qnil );
922+ rb_ary_push (ary , thisupd ? asn1time_to_time (thisupd ) : Qnil );
923+ rb_ary_push (ary , nextupd ? asn1time_to_time (nextupd ) : Qnil );
924+ VALUE ext = rb_ary_new ();
925+ int ext_count = OCSP_SINGLERESP_get_ext_count (single );
926+ for (int j = 0 ; j < ext_count ; j ++ ) {
927+ X509_EXTENSION * x509ext = OCSP_SINGLERESP_get_ext (single , j );
928+ rb_ary_push (ext , ossl_x509ext_new (x509ext ));
929+ }
930+ rb_ary_push (ary , ext );
931+ rb_ary_push (ret , ary );
938932 }
939933
940934 return ret ;
941935}
942936
943- static VALUE ossl_ocspsres_new (OCSP_SINGLERESP * );
937+ static VALUE ossl_ocspsres_new (const OCSP_SINGLERESP * );
944938
945939/*
946940 * call-seq:
@@ -958,17 +952,10 @@ ossl_ocspbres_get_responses(VALUE self)
958952
959953 GetOCSPBasicRes (self , bs );
960954 count = OCSP_resp_count (bs );
961- ret = rb_ary_new2 (count );
955+ ret = rb_ary_new_capa (count );
962956
963957 for (i = 0 ; i < count ; i ++ ) {
964- OCSP_SINGLERESP * sres , * sres_new ;
965-
966- sres = OCSP_resp_get0 (bs , i );
967- sres_new = ASN1_item_dup (ASN1_ITEM_rptr (OCSP_SINGLERESP ), sres );
968- if (!sres_new )
969- ossl_raise (eOCSPError , "ASN1_item_dup" );
970-
971- rb_ary_push (ret , ossl_ocspsres_new (sres_new ));
958+ rb_ary_push (ret , ossl_ocspsres_new (OCSP_resp_get0 (bs , i )));
972959 }
973960
974961 return ret ;
@@ -986,7 +973,6 @@ static VALUE
986973ossl_ocspbres_find_response (VALUE self , VALUE target )
987974{
988975 OCSP_BASICRESP * bs ;
989- OCSP_SINGLERESP * sres , * sres_new ;
990976 OCSP_CERTID * id ;
991977 int n ;
992978
@@ -995,13 +981,7 @@ ossl_ocspbres_find_response(VALUE self, VALUE target)
995981
996982 if ((n = OCSP_resp_find (bs , id , -1 )) == -1 )
997983 return Qnil ;
998-
999- sres = OCSP_resp_get0 (bs , n );
1000- sres_new = ASN1_item_dup (ASN1_ITEM_rptr (OCSP_SINGLERESP ), sres );
1001- if (!sres_new )
1002- ossl_raise (eOCSPError , "ASN1_item_dup" );
1003-
1004- return ossl_ocspsres_new (sres_new );
984+ return ossl_ocspsres_new (OCSP_resp_get0 (bs , n ));
1005985}
1006986
1007987/*
@@ -1110,12 +1090,18 @@ ossl_ocspbres_to_der(VALUE self)
11101090 * OCSP::SingleResponse
11111091 */
11121092static VALUE
1113- ossl_ocspsres_new (OCSP_SINGLERESP * sres )
1093+ ossl_ocspsres_new (const OCSP_SINGLERESP * sres )
11141094{
11151095 VALUE obj ;
1096+ OCSP_SINGLERESP * sres_new ;
11161097
11171098 obj = NewOCSPSingleRes (cOCSPSingleRes );
1118- SetOCSPSingleRes (obj , sres );
1099+ /* OpenSSL 1.1.1 takes a non-const pointer */
1100+ sres_new = ASN1_item_dup (ASN1_ITEM_rptr (OCSP_SINGLERESP ),
1101+ (OCSP_SINGLERESP * )sres );
1102+ if (!sres_new )
1103+ ossl_raise (eOCSPError , "ASN1_item_dup" );
1104+ SetOCSPSingleRes (obj , sres_new );
11191105
11201106 return obj ;
11211107}
@@ -1233,12 +1219,9 @@ static VALUE
12331219ossl_ocspsres_get_certid (VALUE self )
12341220{
12351221 OCSP_SINGLERESP * sres ;
1236- OCSP_CERTID * id ;
12371222
12381223 GetOCSPSingleRes (self , sres );
1239- id = OCSP_CERTID_dup ((OCSP_CERTID * )OCSP_SINGLERESP_get0_id (sres )); /* FIXME */
1240-
1241- return ossl_ocspcertid_new (id );
1224+ return ossl_ocspcid_new (OCSP_SINGLERESP_get0_id (sres ));
12421225}
12431226
12441227/*
0 commit comments