QMailCryptoFwd::SignatureResult QMailCryptoSMIME::sign(QMailMessagePartContainer &part, const QStringList &keys) const { QByteArray signedData, micalg; QMailCryptoFwd::SignatureResult result; result = computeSignature(part, keys, signedData, micalg); if (result != QMailCryptoFwd::SignatureValid) return result; // Set it to multipart/signed content-type. QList<QMailMessageHeaderField::ParameterType> parameters; parameters << QMailMessageHeaderField::ParameterType("micalg", micalg); parameters << QMailMessageHeaderField::ParameterType("protocol", "application/pkcs7-signature"); part.setMultipartType(QMailMessagePartContainerFwd::MultipartSigned, parameters); // Write the signature data in the second part. QMailMessagePart &signature = part.partAt(1); QMailMessageContentDisposition disposition; disposition.setType(QMailMessageContentDispositionFwd::Attachment); disposition.setFilename("smime.p7s"); signature.setContentDisposition(disposition); signature.setBody(QMailMessageBody::fromData(signedData, QMailMessageContentType("application/pkcs7-signature"), QMailMessageBodyFwd::Base64)); return QMailCryptoFwd::SignatureValid; }
void SignedUrl::sign( Url& urlToSign ) { UtlString existingUrlSignature; UtlString urlString; urlToSign.toString( urlString ); if( urlToSign.getUrlParameter( SignatureUrlParamName, existingUrlSignature ) == TRUE ) { OsSysLog::add(FAC_SIP, PRI_DEBUG, "SignedUrl::sign URL '%s' already signed - updating signature", urlString.data() ); } UtlString userInfo; UtlString hostPort; UtlString strSignature; urlToSign.getUserId( userInfo ); urlToSign.getHostWithPort( hostPort ); computeSignature( userInfo, hostPort, strSignature ); urlToSign.setUrlParameter( SignatureUrlParamName, strSignature.data() ); OsSysLog::add(FAC_SIP, PRI_DEBUG, "SignedUrl::sign URL signed: '%s' with signature '%s'", urlString.data(), strSignature.data() ); }
UtlBoolean SignedUrl::isUrlSigned( Url& signedUrl ) { UtlBoolean bUrlProperlySigned; UtlString existingUrlSignature; UtlString urlString; signedUrl.toString( urlString ); if( signedUrl.getUrlParameter( SignatureUrlParamName, existingUrlSignature ) == FALSE ) { bUrlProperlySigned = FALSE; OsSysLog::add(FAC_SIP, PRI_DEBUG, "SignedUrl::isUrlSigned URL '%s' not signed", urlString.data() ); } else { UtlString userInfo; UtlString hostPort; UtlString strReferenceSignature; signedUrl.getUserId( userInfo ); signedUrl.getHostWithPort( hostPort ); computeSignature( userInfo, hostPort, strReferenceSignature ); if( strReferenceSignature.compareTo( existingUrlSignature ) == 0 ) { bUrlProperlySigned = TRUE; OsSysLog::add(FAC_SIP, PRI_DEBUG, "SignedUrl::isUrlSigned URL '%s' is properly signed", urlString.data() ); } else { bUrlProperlySigned = FALSE; OsSysLog::add(FAC_SIP, PRI_DEBUG, "SignedUrl::isUrlSigned URL '%s' does not have a valid signature. " "Expected signature: '%s'", urlString.data(), strReferenceSignature.data() ); } } return bUrlProperlySigned; }