예제 #1
0
func createResponse(config *Config, data *verifyData) (string, error) {
	m := new(pgpmail.Message)
	m.AddHeader("From", config.VerifyEmail)
	m.AddHeader("To", data.sender.String())
	m.AddHeader("Subject", "Nyms Mail Verification")
	m.AddHeader("X-Nyms-Verifier", "response")
	m.AddMultipart(createBody())
	attach, err := createAttachment(data)
	if err != nil {
		return "", err
	}
	m.AddMultipart(attach)
	m.PackMultiparts()
	status := m.Sign(config.KeySource, "")
	if status.Code != pgpmail.StatusSignedOnly {
		return "", fmt.Errorf("signing message failed with status code %d: %s", status.Code, status.FailureMessage)
	}
	response := m.String()
	signed, err := dkimSign(config, response)
	if err != nil {
		logger.Warning("dkim signing failed: %v", err)
		return response, nil
	}
	return signed, nil
}
예제 #2
0
func processEncrypted(m *pgpmail.Message, result *ProcessIncomingResult, passphrase []byte) error {
	status := m.DecryptWith(keymgr.KeySource(), passphrase)
	result.DecryptResult = status.Code
	result.VerifyResult = status.VerifyStatus.Code
	if status.Code == pgpmail.DecryptFailed {
		result.FailureMessage = status.FailureMessage
	} else if status.VerifyStatus.Code == pgpmail.VerifyFailed {
		result.FailureMessage = status.VerifyStatus.FailureMessage
	}
	if status.Code == pgpmail.DecryptPassphraseNeeded && status.KeyIds != nil {
		for _, id := range status.KeyIds {
			result.EncryptedKeyIds = append(result.EncryptedKeyIds, encodeKeyId(id))
		}
	}
	if status.Code == pgpmail.DecryptSuccess {
		result.EmailBody = m.String()
	}
	return nil
}