Emergency check-in due to impending merge to the tip :-) smimetk_branch
authorchrisk%netscape.com
Tue, 13 Jun 2000 20:45:44 +0000
branchsmimetk_branch
changeset 364 3dd51ced498a01123dfd434c1a645677b9f433c6
parent 363 be432b736b56ac6e92594786e7016cf09af70bb3
child 13915 573251835b38ed3e94861b85f155130e5fc5de12
push idunknown
push userunknown
push dateunknown
Emergency check-in due to impending merge to the tip :-) This is a work in progress...
security/nss/cmd/smimetools/cmsutil.c
security/nss/cmd/smimetools/smime
--- a/security/nss/cmd/smimetools/cmsutil.c
+++ b/security/nss/cmd/smimetools/cmsutil.c
@@ -103,17 +103,18 @@ Usage(char *progName)
     fprintf(stderr, " -D            decode a CMS message\n");
     fprintf(stderr, "  -c content   use this detached content\n");
     fprintf(stderr, "  -n           suppress output of content\n");
     fprintf(stderr, "  -h num       generate email headers with info about CMS message\n");
     fprintf(stderr, " -S            create a CMS signed message\n");
     fprintf(stderr, "  -N nick      use certificate named \"nick\" for signing\n");
     fprintf(stderr, "  -T           do not include content in CMS message\n");
     fprintf(stderr, "  -G           include a signing time attribute\n");
-    fprintf(stderr, "  -P           include a S/MIME profile attribute\n");
+    fprintf(stderr, "  -P           include a SMIMECapabilities attribute\n");
+    fprintf(stderr, "  -Y nick      include a EncryptionKeyPreference attribute with cert\n");
     fprintf(stderr, " -E            create a CMS enveloped message (NYI)\n");
     fprintf(stderr, "  -r id,...    create envelope for these recipients,\n");
     fprintf(stderr, "               where id can be a certificate nickname or email address\n");
     fprintf(stderr, "\nCert usage codes:\n");
     fprintf(stderr, "%-25s  0 - certUsageSSLClient\n", " ");
     fprintf(stderr, "%-25s  1 - certUsageSSLServer\n", " ");
     fprintf(stderr, "%-25s  2 - certUsageSSLServerWithStepUp\n", " ");
     fprintf(stderr, "%-25s  3 - certUsageSSLCA\n", " ");
@@ -168,16 +169,17 @@ struct optionsStr {
 struct decodeOptionsStr {
     FILE *contentFile;
     int headerLevel;
     PRBool suppressContent;
 };
 
 struct signOptionsStr {
     char *nickname;
+    char *encryptionKeyPreferenceNick;
     PRBool signingTime;
     PRBool smimeProfile;
     PRBool detached;
 };
 
 struct envelopeOptionsStr {
     char **recipients;
 };
@@ -419,16 +421,20 @@ sign(FILE *out, FILE *infile, char *prog
 	    fprintf(stderr, "ERROR: cannot create CMS signerInfo object.\n");
 	    NSS_CMSMessage_Destroy(cmsg);
 	    return SECFailure;
 	}
     }
     if (signOptions.smimeProfile) {
 	/* TBD */
     }
+    if (signOptions.encryptionKeyPreferenceNick) {
+	/* TBD */
+	/* get the cert, add it to the message */
+    }
 
     if (NSS_CMSSignedData_AddSignerInfo(sigd, signerinfo) != SECSuccess) {
 	fprintf(stderr, "ERROR: cannot add CMS signerInfo object.\n");
 	NSS_CMSMessage_Destroy(cmsg);
 	return SECFailure;
     }
 
     /*
@@ -626,22 +632,23 @@ main(int argc, char **argv)
     decodeOptions.suppressContent = PR_FALSE;
     decodeOptions.headerLevel = -1;
     options.certUsage = certUsageEmailSigner;
     options.password = NULL;
     signOptions.nickname = NULL;
     signOptions.detached = PR_FALSE;
     signOptions.signingTime = PR_FALSE;
     signOptions.smimeProfile = PR_FALSE;
+    signOptions.encryptionKeyPreferenceNick = NULL;
     envelopeOptions.recipients = NULL;
 
     /*
      * Parse command line arguments
      */
-    optstate = PL_CreateOptState(argc, argv, "DSEnN:TGPh:p:i:c:d:o:s:u:r:");
+    optstate = PL_CreateOptState(argc, argv, "DSEnN:TGPY:h:p:i:c:d:o:s:u:r:");
     while ((status = PL_GetNextOpt(optstate)) == PL_OPT_OK) {
 	switch (optstate->option) {
 	case '?':
 	    Usage(progName);
 	    break;
 	
 	case 'D':
 	    mode = DECODE;
@@ -666,16 +673,25 @@ main(int argc, char **argv)
 	    if (mode != SIGN) {
 		fprintf(stderr, "%s: option -N only supported with option -S.\n", progName);
 		Usage(progName);
 		exit(1);
 	    }
 	    signOptions.nickname = strdup(optstate->value);
 	    break;
 
+	case 'Y':
+	    if (mode != SIGN) {
+		fprintf(stderr, "%s: option -Y only supported with option -S.\n", progName);
+		Usage(progName);
+		exit(1);
+	    }
+	    signOptions.encryptionKeyPreferenceNick = strdup(optstate->value);
+	    break;
+
 	case 'T':
 	    if (mode != SIGN) {
 		fprintf(stderr, "%s: option -T only supported with option -S.\n", progName);
 		Usage(progName);
 		exit(1);
 	    }
 	    signOptions.detached = PR_TRUE;
 	    break;
--- a/security/nss/cmd/smimetools/smime
+++ b/security/nss/cmd/smimetools/smime
@@ -201,17 +201,17 @@ sub usage {
 
 #
 # start of main procedures
 #
 
 #
 # process command line options
 #
-unless (getopts('S:E:p:C:')) {
+unless (getopts('S:E:p:C:D')) {
     usage();
     exit 1;
 }
 
 unless (defined($opt_S) or defined($opt_E)) {
     print STDERR "ERROR: -S and/or -E must be specified.\n";
     usage();
     exit 1;
@@ -257,51 +257,69 @@ while (<STDIN>) {
 
 #
 # if there are no MIME entity headers, generate some default ones
 #
 if ($mimeentity eq "") {
     $mimeentity .= "Content-Type: text/plain; charset=us-ascii\n";
     $mimeentity .= "Content-Transfer-Encoding: 7bit\n";
 }
+
 #
 # generate end of header-LF/LF pair
 #
 $mimeentity .= "\n";
 
 #
 # slurp in the entity body
 #
 $saveRS = $/;
 $/ = undef;
 $mimeentity .= <STDIN>;
 $/ = $saveRS;
 
-#
-# canonicalize entity (rudimentary yet)
-#
-$mimeentity =~ s/\n/\r\n/mg;
+if (defined $opt_D) {
+    #
+    # decode
+    #
+
+    
+
+} else {
+    #
+    # encode
+    #
+
+    #
+    # canonicalize inner entity (rudimentary yet)
+    # convert single LFs to CRLF
+    # if no Content-Transfer-Encoding header present:
+    #  if 8 bit chars present, use Content-Transfer-Encoding: quoted-printable
+    #  otherwise, use Content-Transfer-Encoding: 7bit
+    #
+    $mimeentity =~ s/\n/\r\n/mg;
 
-#
-# now do the wrapping
-# we sign first, then encrypt because that's what Communicator needs
-#
-if (defined($opt_S)) {
-    $mimeentity = signentity($mimeentity, $signopts);
+    #
+    # now do the wrapping
+    # we sign first, then encrypt because that's what Communicator needs
+    #
+    if (defined($opt_S)) {
+	$mimeentity = signentity($mimeentity, $signopts);
+    }
+
+    if (defined($opt_E)) {
+	$mimeentity = encryptentity($mimeentity, $encryptopts);	
+    }
+
+    #
+    # XXX sign again to do triple wrapping (RFC2634)
+    #
+
+    #
+    # now write out the RFC822 headers
+    # followed by the final $mimeentity
+    #
+    print $rfc822headers;
+    print "MIME-Version: 1.0 (NSS SMIME - http://www.mozilla.org/projects/security)\n";	# set up the flag
+    print $mimeentity;
 }
 
-if (defined($opt_E)) {
-    $mimeentity = encryptentity($mimeentity, $encryptopts);	
-}
-
-#
-# XXX sign again to do triple wrapping (RFC2634)
-#
-
-#
-# now write out the RFC822 headers
-# followed by the final $mimeentity
-#
-print $rfc822headers;
-print "MIME-Version: 1.0 (NSS SMIME - http://www.mozilla.org/projects/security)\n";	# set up the flag
-print $mimeentity;
-
 exit 0;