Git Product home page Git Product logo

dkimverifier's Introduction

DKIMVerifier 0.1

build_and_test

Features

  • Verification of DKIM signatures (https://datatracker.ietf.org/doc/html/rfc6376)
  • No boolean result: Additional detection of DKIM security pitfalls
    • DKIM has user-configurable parameters that can make a valid DKIM signature pretty useless and this library strives to point out this misconfigured signatures
    • More info: #10
  • DMARC Alignment Policy Verification
    • additionally checks if the DMARC DKIM Alignment policy is correct for valid DKIM signatures
  • Supports DNSSEC via libunbound (and in theory with dnssd)
  • Includes a command line tool: DKIMVerifierTool with extensive output

API

DKIM Verification

public func verifyDKIMSignatures(
  dnsLoopupTxtFunction: @escaping DNSLookupFunctionType,
  emailRaw: String,
  verifyDMARCAlignment: Bool = false
)
  -> DKIMResult

Arguments:

  • dnsLookupTxtFunction: should return txt value for specific domain
  • emailRaw: RFC5322 Message as raw string
  • verifyDMARCAlignment: additional verify DMARC DKIM Alignment for valid signatures (default: false)

Result:

  • status: an overall status, Valid or Insecure if any of the dkim signatures in the mail returned this result
  • signatures: the individual signature results, good to check for DKIM Risks if the overall result is only Valid_Insecure
  • emailFromSender: the extracted email from the From: mail header field
  • extractedDomainFromSender: the extracted domain from the From: mail header field, used for the DKIM SDID and DMARC alignment checks
  • DMARCResult: the dmarc info and alignment check info if requested via verifyDMARCAlignment
public struct DKIMResult: Equatable {
  public var status: DKIMStatus
  public var signatures: [DKIMSignatureResult]

  public var emailFromSender: String?
  public var extractedDomainFromSender: String?
  public var extractedDomainFromSenderIdnaEncoded: String?

  public var dmarcResult: DMARCResult?
}

public struct DKIMSignatureResult: Equatable {
  public var status: DKIMSignatureStatus
  public var info: DKIMSignatureInfo?
  public var dnsInfo: DKIMSignatureDNSInfo?
  public var validatedWithDNSSEC: Bool = false
}

public enum DKIMSignatureStatus: Equatable {
  case Valid
  case Insecure(Set<DKIMRisks>)
  case Error(DKIMError)
}

public enum DKIMRisks: Hashable, Equatable {
  /// third-party signature, DKIM specified domain is not a subdomain or equal to From: E-Mail-Header
  case SDIDNotInFrom(sdid: String, fromDomain: String)
  /// The DKIM RFC only requires the  From: field to be signed, but more fields are recommend else manipulation possible
  /// Subject, Content-Type, Reply-To,... should be signed,  see importantHeaderFields
  case ImportantHeaderFieldNotSigned(name: String)
  /// Using a key size less than LowestSecureKeySize for RSA (default: 2048)
  case InsecureKeySize(size: Int, expected: Int)
  /// Signature Expiration Parameter is in the past
  case SignatureExpired(expirationDate: Date)
  /// could not validate dns requests with DNSSEC
  case ValidatedWithoutDNSSEC

  // Not accepted as a risk anymore (high risk, not used)
  //   -> Ignored in body hash validation, error on additional content
  // case UsingLengthParameter  // only verified to a specific body length

  // Not accepted as a risk anymore (RFC8301) -> Error
  // case UsingSHA1  // insecure hashing algorithm
}

public enum DMARCStatus: Equatable {
  case validDKIMIdentifierAlignment
  case Error(DMARCError)
}

public struct DMARCResult: Equatable {
  public var status: DMARCStatus
  public var fromSenderDomain: String
  public var validDKIMDomains: [String]
  public var validatedWithDNSSEC: Bool

  public var entry: DMARCEntry?
  public var foundPolicyDomain: String?
  public var validDomain: String?
}

dkimverifier's People

Contributors

skomski avatar

Stargazers

 avatar

Watchers

 avatar  avatar

dkimverifier's Issues

Implement DKIM Risks

Handled as Risk

  • ImportantHeaderNotSigned (also mind quantity) (RFC6376) (1)
    • rfc6376 recommends that all important header fields should be signed like for example subject, reply-to, date etc but only from: is required. In the wild various email providers sign much less than they should.
  • SDIDNotInFromHeader (RFC6376, DMARC Alignment Check)
    • SDID means Signing Domain Identifier. DKIM signatures are checked against the SDID provided in the DKIM parameters. This SDID should be same as the Sender in Mail From: Header field but after the DKIM standard third-party signatures are allowed, but which in most cases are unwanted.
  • Check cryptographic key size
    • under 2048 key length should be problematic
  • SignatureExpired
    • DKIM signature timestamp is in the past
  • ValidatedWithoutDNSSEC
    • validate DNS requests with DNSSEC
    • support via libunbound or user configurable dns library

Handled as Error

  • UsingSHA1 (RFC8301)
    • old insecure hash algorithm
    • deprecated and too insecure for a risk
  • UsingLengthField (RFC6376)
    • email content only verified to a specific body length. Content after that open to manipulation.
    • ignored in body hash calculation. Any manipulation results in an understandable error. As a risk not assessable for the end user
  • Multiple or none From: Fields (Forbidden by RFC5322, 1)
    • forbidden by rfc5322
  • Ambiguous (complex) From: addresses and/or with mutiple domains (Forbidden by RFC7489 (DMARC)) (1)
    • following DMARC because means less security problems down the line
    • only one email address allowed in From: Header
  • Ambiguous domains: (ex.: NUL ambiguity and DNS) (1)
  • DuplicateImportantHeaderFields (ex.: two subjects;) (1)
  • handled as an error because independent of signatures and always suspicious for checked headers
  • maybe should be user configurable
  • problematic for user interface applications

(1) https://www.usenix.org/system/files/sec20-chen-jianjun.pdf
RFC6376: DKIM https://datatracker.ietf.org/doc/html/rfc7489
RFC5322: MAIL https://datatracker.ietf.org/doc/html/rfc5322
RFC7489: DMARC https://datatracker.ietf.org/doc/html/rfc7489

Report mailauth bug

Sometimes mailauth does report no dkim signature although it exists. Need to trim down a good test case

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.