Commit 8a58c06e58a834428310c82ba7870729d9bb2bba

  • avatar
  • ol42
  • Tue Oct 13 23:49:58 CEST 2009
fixed compatibility issues with GPGMail
.DS_Store
(2 / 2)
Binary files differ
  
244244
245245 if gpginfo.length == 0
246246 sendmail( rcpArray, encrypted_msg )
247 client.write "250 Ok" + LINESEP
247 client.write "250 OK" + LINESEP
248248 log "mail sent, 250 OK signaled, last line received: " + line
249249 else
250250 log "encryption error occured!"
gpgmime.rb
(39 / 18)
  
8181 # get the range for the complete key-value pair, required to remove key
8282 def getKeyStringRange( key, string, sepchar )
8383 keystring = key+sepchar
84 if string.match(/^#{keystring}/) == nil
84 if string.match(/^#{keystring}/i) == nil
8585 return
8686 end
87 start_index = string.index(/^#{keystring}/)
87 start_index = string.index(/^#{keystring}/i)
8888 cont_str = string[start_index, string.length - start_index]
8989 line_length = cont_str.index(/\r\n[-a-zA-Z0-9_"]/) + 2 # CRLF has to be removed too
9090 [start_index, line_length]
9797
9898 keystring = key+sepchar
9999
100 start_index = string.index(/^#{keystring}/)
100 start_index = string.index(/^#{keystring}/i)
101101 if( start_index != nil )
102102
103103 start_index += keystring.length
157157 # main key with getValueforKey value first
158158 def getValueForSubKey( key, string )
159159 keystring = key+"="
160 /(#{keystring})(.+)(;|#{LINESEP})/m =~ ( string+";" )
160 /(#{keystring})(.+)(;|#{LINESEP})/mi =~ ( string+";" )
161161 if Regexp.last_match(2) != nil
162162 Regexp.last_match(2).chomp
163163 else
169169 # assigns a value to a given sub key, similar to getValueForSubKey
170170 def setValueForSubKey( key, value, string )
171171 keystring = key+"="
172 /(#{keystring})(.+)(;|#{LINESEP})/m =~ ( string+";" )
172 /(#{keystring})(.+)(;|#{LINESEP})/mi =~ ( string+";" )
173173 offset = Regexp.last_match.offset(2)
174174 value_range = [offset[0], offset[1]-offset[0]]
175175
284284 # application where we do have only two attachemts which can be distinguished
285285 # in this way
286286 def getSubContentOfType( type, boundary )
287 if( ( /(Content-Type:)(.*?)(#{type})/ =~ @content_str ) == nil )
287 if( ( /(Content-Type:)(.*?)(#{type})/i =~ @content_str ) == nil )
288288 return nil
289289 end
290290
292292 att_end = att_beg + @content_str[ att_beg, @content_str.length - att_beg ].match( boundary ).offset(0)[0]
293293
294294 att_str = @content_str[ att_beg, att_end - att_beg]
295
296 cont_beg_index = att_str.match(LINESEP+LINESEP).offset(0)[1]
295
296 att_str.match(LINESEP+LINESEP)
297 if Regexp.last_match != nil
298 cont_beg_index = Regexp.last_match.offset(0)[1]
299 else
300 # some GPG/MIME engines unfortunately encrypt obviously with CR instead of CRLF
301 att_str.match("\n\n")
302 if Regexp.last_match != nil
303 cont_beg_index = Regexp.last_match.offset(0)[1]
304 else
305 cont_beg_index = 0
306 end
307 end
308
297309 att_str[ cont_beg_index, att_str.length - cont_beg_index]
298310 end
299311
571571
572572 # check mime type and get boundary
573573 cntType = getContentType()
574
574575 if cntType.match("application\/pgp-encrypted") == nil
575576 return "input stream with wrong content-type, must be pgp-encrypted!"
576577 end
577578 boundary = getValueForSubKey( "boundary", cntType )
578579 /(")(.*?)(")/=~boundary
579 boundary = "--"+Regexp.last_match(2)
580 boundary = "--"+Regexp.last_match(2)
580581
581582 # check PGP/Mime Version ( normally this is in the first attachment )
582 version_str = getSubContentOfType( "application\/pgp-encrypted", boundary )
583 version_str = getSubContentOfType( "application\/pgp-encrypted", boundary )
583584 if version_str==nil || version_str.match("Version: 1") == nil
584585 return "only version 1 for application/pgp-encrypted mime type supported!"
585586 end
615615
616616 # exchange content and attach gpg signature info at the end of the message
617617 @content_str = decrypted_content + LINESEP
618 add_signature( gpgmsg )
619
618
620619 # deliver gpg error code to invoker if any
621620 if gpg_result_code != 0
622621 gpgmsg
623622 else
624 ""
623 if getContentType().match( "application\/pgp-signature" )
624 check_clearsig
625 else
626 add_signature( gpgmsg )
627 ""
628 end
625629 end
626630
627631 end
633633
634634 # checks clear text signature
635635 def check_clearsig
636
636637 # check mime type and get boundary
637638 cntType = getContentType()
638639 if cntType.match("application\/pgp-signature") == nil
644644 boundary = "--"+Regexp.last_match(2)
645645
646646 # extract signed content which must be the first section
647 if @content_str.match( boundary+LINESEP ) == nil
647 # some email clients unfortunately use CR instead of CRLF before encrpytion
648 if @content_str.match( boundary+LINESEP ) == nil && @content_str.match( boundary+"\n" ) == nil
648649 return "input stream does not provide specified boundaries!"
649650 end
650651
651652 signed_content = @content_str[Regexp.last_match.offset(0)[1], @content_str.length]
652653
653 if signed_content.match( LINESEP+boundary ) == nil
654 if signed_content.match( LINESEP+boundary ) == nil && signed_content.match( "\n"+boundary ) == nil
654655 return "input stream does not provide specified boundaries!"
655656 end
656657
657658 signed_content = $`
658659
659 # extract key
660 # extract key
660661 sig_str = getSubContentOfType( "application\/pgp-signature", boundary )
661662 if( sig_str == nil )
662663 return "missing section application/pgp-signature in input stream!"
671671 # invoke gpg subprocess
672672 dummy, gpgmsg, gpg_result_code =
673673 gpg( [], signed_content, "--batch --verify #{sigfilename} -", nil )
674
675
674
676675 # RFC 822 requires originally CRLF, but some mua handle it different
677676 # split encrypted content in original header and content information
678677 splitmatch = signed_content.match( LINESEP+LINESEP )
703703
704704 end
705705
706
707
706708 public
707709
708710 # invokes depending of content type decrypt or check_clearsig
724724 return res
725725
726726 end
727
727728
728729 # delivers an array with all email addresses to public keys
729730 def getPubKeyAddressList