- 
                Notifications
    You must be signed in to change notification settings 
- Fork 182
PKCS7 unsigned/signed attributes support #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Draft
      
      
            rxbynerd
  wants to merge
  4
  commits into
  ruby:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
rubynerd-forks:add-pkcs7-signed-attributes-support
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Draft
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            4 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      0c18627
              
                add PKCS7 "partial" flag support to OpenSSL::PKCS7.sign
              
              
                rxbynerd 879c139
              
                add draft implementation of OpenSSL::PKCS7#finalize / PKCS7_final
              
              
                rxbynerd 45d19cb
              
                WIP implementation of PKCS7::SignerInfo#add_signed_attribute
              
              
                rxbynerd 4b95ee6
              
                replace add_signed_attribute with set_signed_attributes
              
              
                rxbynerd File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -230,12 +230,16 @@ ossl_pkcs7_s_sign(int argc, VALUE *argv, VALUE klass) | |
| pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */ | ||
| flg = NIL_P(flags) ? 0 : NUM2INT(flags); | ||
| ret = NewPKCS7(cPKCS7); | ||
| in = ossl_obj2bio(&data); | ||
|  | ||
| if (!(flg & PKCS7_PARTIAL)) | ||
| in = ossl_obj2bio(&data); | ||
|  | ||
| if(NIL_P(certs)) x509s = NULL; | ||
| else{ | ||
| x509s = ossl_protect_x509_ary2sk(certs, &status); | ||
| if(status){ | ||
| BIO_free(in); | ||
| if (!(flg & PKCS7_PARTIAL)) | ||
| BIO_free(in); | ||
| rb_jump_tag(status); | ||
| } | ||
| } | ||
|  | @@ -244,10 +248,17 @@ ossl_pkcs7_s_sign(int argc, VALUE *argv, VALUE klass) | |
| sk_X509_pop_free(x509s, X509_free); | ||
| ossl_raise(ePKCS7Error, NULL); | ||
| } | ||
|  | ||
| SetPKCS7(ret, pkcs7); | ||
| ossl_pkcs7_set_data(ret, data); | ||
|  | ||
| if (!(flg & PKCS7_PARTIAL)) | ||
| ossl_pkcs7_set_data(ret, data); | ||
|  | ||
| ossl_pkcs7_set_err_string(ret, Qnil); | ||
| BIO_free(in); | ||
|  | ||
| if (!(flg & PKCS7_PARTIAL)) | ||
| BIO_free(in); | ||
|  | ||
| sk_X509_pop_free(x509s, X509_free); | ||
|  | ||
| return ret; | ||
|  | @@ -863,6 +874,24 @@ ossl_pkcs7_to_pem(VALUE self) | |
| return str; | ||
| } | ||
|  | ||
| static VALUE | ||
| ossl_pkcs7_finalize(VALUE self, VALUE data, VALUE flags) | ||
| { | ||
| PKCS7 *pkcs7; | ||
| BIO *in; | ||
|  | ||
| GetPKCS7(self, pkcs7); | ||
|  | ||
| int flg = NIL_P(flags) ? 0 : NUM2INT(flags); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: Until we drop support for Ruby 2.6, we have to avoid C99 features ( | ||
| in = ossl_obj2bio(&data); | ||
|  | ||
| if (!PKCS7_final(pkcs7, in, flg)) { | ||
| ossl_raise(ePKCS7Error, NULL); | ||
| }; | ||
|  | ||
| return self; | ||
| } | ||
|  | ||
| /* | ||
| * SIGNER INFO | ||
| */ | ||
|  | @@ -943,6 +972,28 @@ ossl_pkcs7si_get_signed_time(VALUE self) | |
| return Qnil; | ||
| } | ||
|  | ||
| static VALUE | ||
| ossl_pkcs7si_set_signed_attributes(VALUE self, VALUE ary) | ||
| { | ||
| PKCS7_SIGNER_INFO *p7si; | ||
| STACK_OF(X509_ATTRIBUTE) *sk; | ||
| int status, result; | ||
|  | ||
| GetPKCS7si(self, p7si); | ||
| Check_Type(ary, T_ARRAY); | ||
|  | ||
| // TODO: reset attributes | ||
|  | ||
| // build list of x509 attrs of length RARRAY_LEN(ary) | ||
| sk = ossl_protect_x509_attr_ary2sk(ary, &status); | ||
|  | ||
| result = PKCS7_set_signed_attributes(p7si, sk); | ||
|  | ||
| fprintf(stderr, "set signed attributes result is: '%d'\n", result); | ||
|  | ||
| return Qtrue; | ||
| } | ||
|  | ||
| /* | ||
| * RECIPIENT INFO | ||
| */ | ||
|  | @@ -1052,6 +1103,7 @@ Init_ossl_pkcs7(void) | |
| rb_define_method(cPKCS7, "to_pem", ossl_pkcs7_to_pem, 0); | ||
| rb_define_alias(cPKCS7, "to_s", "to_pem"); | ||
| rb_define_method(cPKCS7, "to_der", ossl_pkcs7_to_der, 0); | ||
| rb_define_method(cPKCS7, "finalize", ossl_pkcs7_finalize, 2); | ||
|  | ||
| cPKCS7Signer = rb_define_class_under(cPKCS7, "SignerInfo", rb_cObject); | ||
| rb_define_const(cPKCS7, "Signer", cPKCS7Signer); | ||
|  | @@ -1060,6 +1112,7 @@ Init_ossl_pkcs7(void) | |
| rb_define_method(cPKCS7Signer, "issuer", ossl_pkcs7si_get_issuer, 0); | ||
| rb_define_method(cPKCS7Signer, "serial", ossl_pkcs7si_get_serial,0); | ||
| rb_define_method(cPKCS7Signer,"signed_time",ossl_pkcs7si_get_signed_time,0); | ||
| rb_define_method(cPKCS7Signer, "signed_attributes=", ossl_pkcs7si_set_signed_attributes, 1); | ||
|  | ||
| cPKCS7Recipient = rb_define_class_under(cPKCS7,"RecipientInfo",rb_cObject); | ||
| rb_define_alloc_func(cPKCS7Recipient, ossl_pkcs7ri_alloc); | ||
|  | @@ -1080,4 +1133,5 @@ Init_ossl_pkcs7(void) | |
| DefPKCS7Const(BINARY); | ||
| DefPKCS7Const(NOATTR); | ||
| DefPKCS7Const(NOSMIMECAP); | ||
| DefPKCS7Const(PARTIAL); | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PKCS7#add_dataseems to do the similar thing asPKCS7_final(p7, in, PKCS7_BINARY)already.