Passing Authenticated Messages

To pass authenticated messages between MSMQ and another message queue system, the connector application (both transparent and non-transparent applications) must retrieve all the properties needed for authentication.

Transparent connector applications must perform different operations depending on the direction of the messages. If the message is going from the foreign application to MSMQ, the connector application needs to translate new property values and pass the new values on to MSMQ. If the messages are being sent from MSMQ to the other message queue system, the connector application must translate new property values, then pass both them and the original values on to the foreign application. The original values are needed to generate the hash value used to authenticate the signature.

Non-transparent applications perform the security operations (verify signature) so there is no need to pass on security properties. However, the applications do need to indicate that the message was verified when it passes the message on.

The code needed to perform security operations varies for each application. However, the pseudo-code provided in the following sample shows the basic elements needed to authenticate a message.

When messages are being sent from another message queue system to MSMQ, non-transparent applications must have access to the private signing keys of all the users on the foreign side. The application must compute the message's hash value, encrypt the hash value by applying the user's private signing key, then pass the message on to MSMQ.

Signature Verification Pseudo Code

The following code describes the basic elements needed to authenticate a message.
Retrieve cryptographic provider information needed to perform the cryptographic operation required for signature verification.
CryptProvName = GetMessageProperty(Message, PROPID_M_PROV_NAME)
CryptProvType = GetMessageProperty(Message, PROPID_M_PROV_TYPE)
 

Initialize the crpytographic provider.

CryptProvider = AcquireCrpytoraphicConext(
                               CryptProvName,
                               CryptProvType)
 

Get the hash algorithm identifier and initialize a hash object. This object is used to perform the hashing and signature-verification operations.

HashAlogorithm = GetMessageProperty(Message, PROPID_M_HASH_ALG)
HashObject = GetHashObject(CryptProvider, HashAlogorithm)
 

Get the six message properties that are required for calculating the hash value for the message.

CorrelationId = GetMessageProperty(Message, PROPID_M_CORRELATIONID)
AppSpecific = GetMessageProperty(Message, PROPID_M_APPSPECIFIC)
MessageBody = GetMessageProperty(Message, PROPID_M_BODY)
MessageLabel = GetMessageProperty(Message,  PROPID_M_LABEL)
RespQueueFormat = GetMessageProperty(Message, PROPID_M_RESP_QUEUE)
AdminQueueFormat = GetMessageProperty(Message,  PROPID_M_ADMIN_QUEUE)

Compute the hash value for the message by adding (in order) each message property to the hash value. The order in which the properties are added is important. Changing the calculation order of the message properties will cause signature verification to fail.

HashData(HashObject, CorrelationId)
HashData(HashObject, AppSpecific)
if NotEmpty(MessageBody)
        HashData(HashObject, MessageBody)
if NotEmpty(MessageLabel)
        HashData(HashObject, MessageLabel)
if NotEmpty(RespQueueFormat)
        HashData(HashObject, RespQueueFormat)
if NotEmpty(AdminQueueFormat)
        HashData(HashObject, AdminQueueFormat)

Get the message signature.

MessageSignature = GetMessageProperty(Message, PROPID_M_SIGNATURE)

Get the sender's certificate.

SenderCert = GetMessageProperty(Message, PROPID_M_SENDER_CERT)
 

Get the sender's public key out from the sender's certificate.

SenderPublicKey = GetPublicKeyFromCertificate(CryptProvider,
SenderCert)

Verify the signature of the message according to the message hash value and the sender's public key.

VerifySignature(HashObject, SenderPublicKey, MessageSignature)
 

The result of the verify signature function indicates whether or not the signature is valid.


© 1997 by Microsoft Corporation. All rights reserved.