Пример #1
0
func processOutgoingMail(body string, sign, encrypt bool, passphrase string, result *ProcessOutgoingResult) error {
	m, err := pgpmail.ParseMessage(body)
	if err != nil {
		return err
	}
	if !needsOutgoingProcessing(m) {
		return nil
	}

	if !encrypt {
		if sign {
			status := m.Sign(keymgr.KeySource(), passphrase)
			processOutgoingStatus(m, status, result)
			return nil
		}
		return nil
	}

	if sign {
		status := m.EncryptAndSign(keymgr.KeySource(), passphrase)
		processOutgoingStatus(m, status, result)
	} else {
		status := m.Encrypt(keymgr.KeySource())
		processOutgoingStatus(m, status, result)
	}
	return nil
}
Пример #2
0
func getEntityByEmail(email string) *openpgp.Entity {
	if k, _ := keymgr.KeySource().GetSecretKey(email); k != nil {
		return k
	}
	k, _ := keymgr.KeySource().GetPublicKey(email)
	return k
}
Пример #3
0
func getEntityByKeyId(keyId string) *openpgp.Entity {
	id, err := decodeKeyId(keyId)
	if err != nil {
		logger.Warning(fmt.Sprint("Error decoding received key id: ", err))
		return nil
	}
	if k := keymgr.KeySource().GetSecretKeyById(id); k != nil {
		return k
	}
	return keymgr.KeySource().GetPublicKeyById(id)
}
Пример #4
0
func processSigned(m *pgpmail.Message, result *ProcessIncomingResult) error {
	status := m.Verify(keymgr.KeySource())
	result.VerifyResult = status.Code
	if status.Code == pgpmail.VerifyFailed {
		result.FailureMessage = status.FailureMessage
	}
	if status.SignerKeyId != 0 {
		result.SignerKeyId = encodeKeyId(status.SignerKeyId)
	}
	return nil
}
Пример #5
0
func (*Protocol) UnlockPrivateKey(args UnlockPrivateKeyArgs, result *bool) error {
	logger.Info("Processing.UnlockPrivateKey")
	id, err := decodeKeyId(args.KeyId)
	if err != nil {
		return err
	}
	k := keymgr.KeySource().GetSecretKeyById(id)
	if k == nil {
		return errors.New("No key found for given KeyId")
	}
	ok, err := keymgr.UnlockPrivateKey(k, []byte(args.Passphrase))
	if err != nil {
		return err
	}
	*result = ok
	return nil
}
Пример #6
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
}