...

Source file src/github.com/letsencrypt/boulder/core/challenges.go

Documentation: github.com/letsencrypt/boulder/core

     1  package core
     2  
     3  import "fmt"
     4  
     5  func newChallenge(challengeType AcmeChallenge, token string) Challenge {
     6  	return Challenge{
     7  		Type:   challengeType,
     8  		Status: StatusPending,
     9  		Token:  token,
    10  	}
    11  }
    12  
    13  // HTTPChallenge01 constructs a random http-01 challenge. If token is empty a random token
    14  // will be generated, otherwise the provided token is used.
    15  func HTTPChallenge01(token string) Challenge {
    16  	return newChallenge(ChallengeTypeHTTP01, token)
    17  }
    18  
    19  // DNSChallenge01 constructs a random dns-01 challenge. If token is empty a random token
    20  // will be generated, otherwise the provided token is used.
    21  func DNSChallenge01(token string) Challenge {
    22  	return newChallenge(ChallengeTypeDNS01, token)
    23  }
    24  
    25  // TLSALPNChallenge01 constructs a random tls-alpn-01 challenge. If token is empty a random token
    26  // will be generated, otherwise the provided token is used.
    27  func TLSALPNChallenge01(token string) Challenge {
    28  	return newChallenge(ChallengeTypeTLSALPN01, token)
    29  }
    30  
    31  // NewChallenge constructs a random challenge of the given kind. It returns an
    32  // error if the challenge type is unrecognized. If token is empty a random token
    33  // will be generated, otherwise the provided token is used.
    34  func NewChallenge(kind AcmeChallenge, token string) (Challenge, error) {
    35  	switch kind {
    36  	case ChallengeTypeHTTP01:
    37  		return HTTPChallenge01(token), nil
    38  	case ChallengeTypeDNS01:
    39  		return DNSChallenge01(token), nil
    40  	case ChallengeTypeTLSALPN01:
    41  		return TLSALPNChallenge01(token), nil
    42  	default:
    43  		return Challenge{}, fmt.Errorf("unrecognized challenge type %q", kind)
    44  	}
    45  }
    46  

View as plain text