Commit Graph

3462 Commits

Author SHA1 Message Date
Daniel b64e51fe51
Adds reconnect handling for SMTP 421 events.
This commit allows the mailer to treat a SMTP 421 err as an event that
should produce a reconnect attempt. Issue #2249 describes a case where
we see this SMTP error code from the remote server when our connection
has been idle for too long. We now reconnect when this happens rather
than failing ungracefully.

The logic in the `mail-test-srv` used to force a number of initial
connections to be disconnected is changed such that half of these forced
disconnects are the normal clean connection close and half are a SMTP
421. This allows the existing integration test for server disconnects to
be reused to test the 421 reconnect logic.
2016-10-19 16:07:49 -04:00
Daniel abfdce6e0a
Moves `mailer.Connect()` closer to `mailer.SendMail()`.
Per #2250 when we connect to the remote SMTP server at start-up time by
calling `mailer.Connect()` but do not actually call `mailer.SendMail()`
until after we have done some potentially expensive/time-consuming work
we are liable to have our connection closed due to timeout.

This commit moves the `Connect()` call in `expiration-mailer` and
`notify-mailer` to be closer to where the actual messages are sent via
`SendMail()`.
2016-10-19 14:33:05 -04:00
Daniel 336a68e582
Use `bmail` for local boulder mail package import.
This commit updates the `expiration-mailer` to import `boulder/mail` as
`bmail` to differentiate from upstream `mail` the same way that the
`notify-mailer` does.
2016-10-19 13:57:11 -04:00
Daniel McCarney 46306b07b9 Adds "SelectFoo" functions for each DB type. (#2259)
In #2178 we moved to explicit `SELECT` statements using a set of `const`
fields for each type to support db migrations and forward compatibility.

This commit removes the temptation to interpolate queries by providing
convenience `SelectFoo` functions for each type allowing the caller to
provide the `WHERE` clause and arguments.

Resolves #2214.
2016-10-19 13:44:37 -04:00
Jacob Hoffman-Andrews 404e9682b1 Improve error messages. (#2256)
Quote rejected hostnames.
Include term "global" when rejecting based on global rate limit.

Fixes #2252
2016-10-18 10:15:21 -07:00
Daniel McCarney 27d531101f Store new authorizations in the `authz` table (#2219)
To remove challenges with expired/pending authz's when they are deleted we want to introduce a foreign key relationship to the challenges table's authorizationID field with instruction to cascade on delete (#2155). As pointed out in a comment this is made difficult by the current usage of a separate pendingAuthorizations table for pending authorizations.

To be able to remove the pendingAuthorizations table entirely (#2163) we need to first stop using it. This PR introduces the code changes required to achieve this.

Notes:

The SA's NewPendingAuthorization function was updated to store all new pending auths in the authz table and to ensure the status is StatusPending.
The SA's GetAuthorization, UpdatePendingAuthorization, FinalizeAuthorization, and RevokeAuthorizationsByDomain functions were updated to properly handle the fact that a pending authz could be in either the pendingAuthorizations table, or the authz table, and to do the right thing accordingly.
Several places in the RA unit tests created a pending authorization with a status "Valid", then finalized it later. This broke when NewPendingAuthorization was changed to enforce Pending status before creating the authz row since the FinalizeAuthorization code expected to only finalize Valid rows. To fix this some of the RA unit tests were changed to explicitly set status to Valid before calling FinalizeAuthorization. This matches the true intention of the tests to quickly create a pending & then finalized authorization.
The expired-authz-purger utility was updated to purge from both the pendingAuthorizations and authz table as required.
The return values of RevokeAuthorizationsByDomain have changed slightly. Previously it returned a 2 element array where the first element was the number of pending authorizations revoked and the second element was the number of finalized authorizations revoked. This is changed so that now it is the number of rows from the pendingAuthorizations and authz tables respectively. E.g. the second count for the authz table may now include non-finalized authzs in its count of affected rows. The admin-revoker is the only place that used this SA method and it was updated appropriately to describe the "rows" change.
The "purger" database user needs to have a new GRANT SELECT, DELETE for the authz table in addition to its existing GRANT for the pendingAuthorizations table.
This resolves #2162
2016-10-18 09:39:59 -07:00
Jacob Hoffman-Andrews faee874c1d Revert "Update google/certificate-transparency dependency. (#2242)" (#2255)
This reverts commit 277cdf1638.

The updated dependencies caused breakage on Go 1.5, which we are still running in prod.
2016-10-17 15:35:18 -07:00
Jacob Hoffman-Andrews b37766c3cb Revert "Update google/certificate-transparency dependency. (#2242)"
This reverts commit 277cdf1638.
2016-10-17 15:20:08 -07:00
Roland Bracewell Shoemaker 09483007bd Cleanup gRPC metric formatting (#2218)
Based on experience with the new gRPC staging deployment. gRPC generates `FullMethod` names such as `-ServiceName-MethodName` which can be confusing. For client calls to a service we actually want something formatted like `ServiceName-MethodName` and for server requests we want just `MethodName`.

This PR adds a method to clean up the `FullMethod` names returned by gRPC and formats them the way we expect.
2016-10-14 10:26:13 -07:00
Jacob Hoffman-Andrews 277cdf1638 Update google/certificate-transparency dependency. (#2242)
Mostly this pulls in
https://github.com/google/certificate-transparency/pull/1275, which means we
don't log as much garbage when CT is having trouble. It also pulls in various
other updates.
2016-10-12 13:49:13 -04:00
Jacob Hoffman-Andrews 131c953b7a Merge pull request #2243 from letsencrypt/cpu-futureweb-psl-bump
Updates publicsuffix-go to +cd40c0.
2016-10-12 10:36:56 -07:00
Daniel 652d61538b Updates publicsuffix-go to +cd40c0.
This PR updates the `publicsuffix-go` dependency to upstream HEAD
(commit `3316aa3feceb68fa73009112eddd387500cd40c0`).

Per CONTRIBUTING.md I verified the project unit tests:

```
daniel@XXXXXXX:~/go/src/github.com/weppos/publicsuffix-go/publicsuffix$ git show -s
commit 3316aa3feceb68fa73009112eddd387500cd40c0
Author: Simone Carletti <weppos@weppos.net>
Date:   Wed Oct 12 10:05:18 2016 +0200

    autopull: 2016-10-12T06:00:21Z (#25)

daniel@XXXXXXX:~/go/src/github.com/weppos/publicsuffix-go/publicsuffix$ go test -v ../...
?     github.com/weppos/publicsuffix-go/cmd/gen [no test files]
?     github.com/weppos/publicsuffix-go/cmd/load  [no test files]
=== RUN   TestPublicSuffix
--- PASS: TestPublicSuffix (0.00s)
=== RUN   TestEffectiveTLDPlusOne
--- PASS: TestEffectiveTLDPlusOne (0.00s)
PASS
ok    github.com/weppos/publicsuffix-go/net/publicsuffix  0.007s
=== RUN   TestValid
--- PASS: TestValid (0.00s)
=== RUN   TestIncludePrivate
--- PASS: TestIncludePrivate (0.00s)
=== RUN   TestPsl
--- PASS: TestPsl (0.02s)
=== RUN   TestNewListFromString
--- PASS: TestNewListFromString (0.00s)
=== RUN   TestNewListFromFile
--- PASS: TestNewListFromFile (0.00s)
=== RUN   TestListAddRule
--- PASS: TestListAddRule (0.00s)
=== RUN   TestListFind
--- PASS: TestListFind (0.00s)
=== RUN   TestNewRule_Normal
--- PASS: TestNewRule_Normal (0.00s)
=== RUN   TestNewRule_Wildcard
--- PASS: TestNewRule_Wildcard (0.00s)
=== RUN   TestNewRule_Exception
--- PASS: TestNewRule_Exception (0.00s)
=== RUN   TestRuleMatch
--- PASS: TestRuleMatch (0.00s)
=== RUN   TestRuleDecompose
--- PASS: TestRuleDecompose (0.00s)
=== RUN   TestLabels
--- PASS: TestLabels (0.00s)
=== RUN   TestCookieJarList
--- PASS: TestCookieJarList (0.00s)
PASS
ok    github.com/weppos/publicsuffix-go/publicsuffix  0.026s
```
2016-10-12 13:07:03 -04:00
Jacob Hoffman-Andrews e37ffa156e Check out a specific tag for Certbot integration tests. (#2240)
Fixes CI breakage.
2016-10-11 15:37:22 -07:00
Jacob Hoffman-Andrews 070114a2e4 Check out a specific tag for Certbot integration tests. 2016-10-11 15:00:55 -07:00
Daniel McCarney 83e713683f Adds `notafter-backfiller` cmd. (#2227)
The "20160817143417_AddCertStatusNotAfter.sql" db migration adds a "notAfter" column to the certificateStatus database table. This field duplicates the contents of the certificates table "expires" column. This enables performance improvements (see #1864) for both the ocsp-updater and the expiration-mailer utilities.

Since existing rows will have a NULL value in the new field the notafter-backfill utility exists to perform a one-time update of the existing certificateStatus rows to set their notAfter column based on the data that exists in the certificates table.

This follows on https://github.com/letsencrypt/boulder/pull/2177 and requires that the migration be applied & the feature flag set accordingly before use.

Fixes #2237.
2016-10-11 14:38:40 -07:00
Ben Irving 00708708e4 Factor out JSON writing in WFE (#2226)
This PR, removes some duplication in the WFE in regards to writing a JSON response. Fixes #2156
2016-10-11 14:29:57 -04:00
Roland Bracewell Shoemaker 5fabc90a16 Add IDN support (#2215)
Add feature flagged support for issuing for IDNs, fixes #597.

This patch expects that clients have performed valid IDN2008 encoding on any label that includes unicode characters. Invalid encodings (including non-compatible IDN2003 encoding) will be rejected. No script-mixing or script exclusion checks are performed as we assume that if a name is resolvable that it conforms to the registrar's policies on these matters and if it uses non-standard scripts in sub-domains etc that browsers should be the ones choosing how to display those names.

Required a full update of the golang.org/x/net tree to pull in golang.org/x/net/idna, all test suites pass.
2016-10-06 13:05:37 -04:00
Roland Bracewell Shoemaker 9648e1cf85 Fix config-next features location and registration status validity check (#2225)
Move features sections to the correct JSON object and only test registration validity if regCheck is true

* Pull other flag up to correct level

* Only check status update when status is non-empty
2016-10-05 12:31:59 -04:00
Daniel McCarney d58987e087 Allows OS to choose listener port. (#2223)
This commit fixes #2190 by allowing the OS to choose what port the test
Listener's bind to. This allows the tests to be run concurrently
without panicing when they all try to bind the same TCP port.
2016-10-03 15:04:24 -07:00
Blake Griffith d2cf6ee126 Fixes RA `DeactivateRegistration` err message typo (#2222) 2016-10-03 15:20:43 -04:00
Jacob Hoffman-Andrews 96fc0b264d Reject IPAddresses and EmailAddresses earlier. (#2213)
Previously, if we received a CSR with IPAddress or EmailAddress SANs, we would
ignore those fields, issuing only for the DNSNames in the CSR. However, we would
later check in MatchesCSR that the CSR's IPAddresses and EmailAddresses matches
those in the issued certificate. This check would fail, serving a 500 to the end
user.

Instead, we now reject the CSR earlier in the process, and send a
meaningful error message.

Fixes #2203
2016-10-03 10:22:44 -07:00
Daniel McCarney 4c9cf065a8 `certificateStatus` table optimizations (Part One) (#2177)
This PR adds a migration to create two new fields on the `certificateStatus` table: `notAfter` and `isExpired`. The rationale for these fields is explained in #1864. Usage of these fields is gated behind `features.CertStatusOptimizationsMigrated` per [CONTRIBUTING.md](https://github.com/letsencrypt/boulder/blob/master/CONTRIBUTING.md#gating-migrations). This flag should be set to true **only** when the `20160817143417_CertStatusOptimizations.sql` migration has been applied.

Points of difference from #2132 (the initial preparatory "all-in-one go" PR):
**Note 1**: Updating the `isExpired` field in the OCSP updater can not be done yet, the `notAfter` field needs to be fully populated first - otherwise a separate query or a messy `JOIN` would have to be used to determine if a certStatus `isExpired` by using the `certificates` table's `expires` field. 
**Note 2**: Similarly we can't remove the `JOIN` on `certificates` from the `findStaleOCSPResponse` query yet until all DB rows have `notAfter` populated. This will happen in a separate **Part Two** PR.
2016-09-30 14:52:19 -04:00
Roland Bracewell Shoemaker c6e3ef660c Re-apply 2138 with proper gating (#2199)
Re-applies #2138 using the new style of feature-flag gated migrations. Account deactivation is gated behind `features.AllowAccountDeactivation`.
2016-09-29 17:16:03 -04:00
Roland Bracewell Shoemaker f84eaef99e Mention we used new-authz instead of application requirements in relevant sections (#2216) 2016-09-29 17:14:12 -04:00
Jacob Hoffman-Andrews 332b019b99 Split grpc/util.go into client and server. (#2212)
Having files or packages named util is not great, because they wind up
attracting lots of small, unrelated functionality.
2016-09-29 10:53:17 -07:00
Daniel McCarney 58bac84707 Describe certificate revocation divergence. (#2211)
This PR adds a divergence to the acme-divergence doc for Section 6.6 "Certificate Revocation". Boulder does not currently support authorizing a revocation request using an arbitrary account key that is authorized for the same domains as in the certificate.
2016-09-28 09:16:39 -07:00
Jacob Hoffman-Andrews 5835081e47 Change review approval to use GitHub's mechanism. (#2210) 2016-09-28 11:56:13 -04:00
Roland Bracewell Shoemaker 1390f376e1 Use explicit SELECT statements instead of wildcards (#2178)
Fixes #2160.

When we use Gorp's built-in `Get` method, it generates `SELECT *` queries. If we do a migration without a simultaneous change of the data structure, Gorp will subsequently error out when it sees a column in the output of the `SELECT *` which doesn't have a corresponding field in the struct it is trying to marshal. In order to be forward compatible with schema changes, we need to always use `SELECT a, b, c`, where `a`, `b`, and `c` are columns / fields in the current struct.
2016-09-28 08:32:38 -07:00
Daniel McCarney 343c8a2465 Allows setting `$TESTPATHS` external to `test.sh`. (#2201)
Unlike the `$GOTESTFLAGS` var there was no way to pass in a default
value to `test.sh` via `docker-compose -e` to indicate you only want to
run specific unit tests.

This commit puts the default `$TESTPATHS` into `$DEFAULT_TESTPATHS` and
assigns it to `$TESTPATHS` only if there isn't already a `$TESTPATHS`
value provided.

Example usage, running just the SA unit tests, with the "next" config,
using `-race -v`:

```
  docker-compose run -e BOULDER_CONFIG_DIR="test/config-next"
    -e RUN="unit" -e GOTESTFLAGS="-v -race"
    -e TESTPATHS="github.com/letsencrypt/boulder/sa" boulder ./test.sh
```
2016-09-27 10:33:44 -07:00
Daniel McCarney 8c2823ff83 Local DB migration improvements (`-next` directory, auto-migrate) (#2206)
This PR makes two improvements to how we handle migrations locally:

1)  Prior to this PR an optimization was present in `test/create_db.sh` that would `exit 0` if the `boulder_sa_integration` database existed. This early exit meant that after the first invocation of `create_db.sh` no further `goose` migrations would be applied unless the operator dropped their databases or edited the script.

This PR reworks the existing DB optimization so that it only skips the `CREATE DATABASE` statements and allows `goose` to try and apply migrations. This doesn't result in significantly longer start up times because Goose is smart enough to know when no migrations are required and outputs something similar to:
  `goose: no migrations to run. current version: 20160602142227`

This should address #2174.

2) This PR also implements a separate `sa/_db-next/` directory for "pending" migrations. This is meant to follow the "test/config" vs "test/config-next" approach to managing changes that are developed but not yet activated in production.

Migrations that are to-be-performed by Ops should be created in the `sa/_db-next` directory first. Once they have been performed by ops in staging/prod and the config flag gate for the migration (see CONTRIBUTING.md) has been set to true, the migration can be moved from `_db-next` to `_db`.

By default all pending migrations from the `-next` directory are applied in the local dev env. If you **do not** wish these migrations to be applied then set the `APPLY_NEXT_MIGRATIONS` env var to false. E.g.:  
   `docker-compose run -eAPPLY_NEXT_MIGRATIONS=false boulder`

This should address #2195
2016-09-26 21:37:05 -07:00
Daniel McCarney d2d5326d2b Updates publicsuffix-go to +81e759 (#2209)
This commit bumps the `publicsuffix-go` dependency to revision
c1cd939ff293bbb87df3691068165868f081e759.
2016-09-26 18:11:27 -07:00
Daniel McCarney 409f1623e6 Retires `LookupIPv6` VA flag. (#2205)
The LookupIPv6 flag has been enabled in production and isn't required anymore. This PR removes the flag entirely.

The errA and errAAAA error handling in LookupHost is left as-is, meaning that a non-nil errAAAA will not be returned to the caller. This matches the existing behaviour, and the expectations of the TestDNSLookupHost unit tests.

This commit also removes the tests from TestDNSLookupHost that tested the LookupIPv6 == false behaviours since those are no longer implemented.

Resolves #2191
2016-09-26 18:00:01 -07:00
Roland Bracewell Shoemaker e18f4e7457 revert expiration-mailer clientName change (#2207)
This required a corresponding change to AMQP permissions, to be scheduled in the future.
2016-09-26 10:37:17 -07:00
Roland Bracewell Shoemaker 96cd5d449b Update flag gating docs (#2198)
Clarify a few things now `features` is a thing.
2016-09-21 14:50:20 -07:00
Roland Bracewell Shoemaker 7f0b7472e2 Add gRPC support to CA (#2193)
Fixes #2171.
2016-09-21 14:13:43 -07:00
Daniel McCarney da979e9c35 Fixes misplaced `*` in flag migration e.g. (#2197)
The embedded `personModelv1` in the `personModelv2` struct should not be
a pointer. The instantiation code later on already uses
`personModelv1{}` instead of `&personModelv1{}` and does not need
updating, just the initial struct definition.
2016-09-21 11:26:18 -07:00
Roland Bracewell Shoemaker 239bf9ae0a Very basic feature flag impl (#1705)
Updates #1699.

Adds a new package, `features`, which exposes methods to set and check if various internal features are enabled. The implementation uses global state to store the features so that services embedded in another service do not each require their own features map in order to check if something is enabled.

Requires a `boulder-tools` image update to include `golang.org/x/tools/cmd/stringer`.
2016-09-20 16:29:01 -07:00
Jacob Hoffman-Andrews e1bc1e5b29 Update config from config-next. (#2175)
Set feature flags:

"reuseValidAuthz": true,
"authorizationLifetimeDays": 90,
"pendingAuthorizationLifetimeDays": 7,
"CAASERVFAILExceptions": "test/caa-servfail-exceptions.txt",
"lookupIPV6": true,
"allowAuthzDeactivation": true,

Remove BaseURL.
Remove trailing slash on CT log URL.
All files now have trailing newlines.
2016-09-19 14:08:36 -07:00
Daniel McCarney b824f31a4c `notify-mailer` graceful handling of `sql.ErrNoRows`. (#2185)
* Fixes `mockEmailResolver` to return `sql.ErrNoRows`.

This commit reproduces the error observed in #2183 where a registration
ID is provided that doesn't match a row with a valid contact.

First a bug is fixed in the ID range check done by the
`mockEmailResolver` - it was using a `||` where it should have been
using a `&&` and also had a `> 0` where it needed `>= 0`, oops! slipped
past review!

Second the `mockEmailResolver` is modified to return `sql.ErrNoRows`
when the index is out of bounds for the mock data.

Lastly a ID of `999` is added to the `TestResolveEmails` function to
elicit the "mailer.send returned error: sql: no rows in result set"
error.

* Handles `sql.ErrNoRows` in `emailsForReg`.

This commit fixes #2183 (and the failing unit test introduced in the
prior commit) by handling `sql.ErrNoRows` in `emailsForReg` gracefully.

* Clarfies mockEmailResolver comment
2016-09-19 12:14:48 -07:00
Daniel McCarney 46bda771d4 Updates flag-gated migration docs (#2186)
Updates the `isWizard` flag gated migration docs to reflect lessons learned writing #2177 in the described style.
2016-09-19 11:48:10 -07:00
Roland Bracewell Shoemaker 2c966c61b2 Revert "Allow account deactivation (#2138)" (#2188)
This reverts commit 6f3d078414, reversing
changes made to c8f1fb3e2f.
2016-09-19 11:20:41 -07:00
Jacob Hoffman-Andrews c6af5d1902 Add details about flag-gating DB migrations. (#2179) 2016-09-19 08:46:12 -07:00
Jacob Hoffman-Andrews f21a7e5ad2 Fix non-Docker integration test. (#2184)
Use labels ending in _key for private key labels.
Create two separate slots in make-softhsm rather than overwriting a single slot.
Update make-softhsm instructions to point out both files to edit.
Improve error output from integation test.
2016-09-16 18:21:33 -07:00
Jacob Hoffman-Andrews 68f8b686af Remove pid from stats. (#2182) 2016-09-16 10:56:45 -07:00
Jacob Hoffman-Andrews 87fee12d6c Improve single-ocsp command (#2181)
Output base64-encoded DER, as expected by ocsp-responder.
Use flags instead of template for Status, ThisUpdate, NextUpdate.
Provide better help.
Remove old test (wasn't run automatically).
Add it to integration test, and use its output for integration test of issuer ocsp-responder.

Add another slot to boulder-tools HSM image, to store root key.
2016-09-15 15:28:54 -07:00
Jacob Hoffman-Andrews 104f409a5e Put PKCS11_PROXY_SOCKET in docker-compose.yml. (#2167) 2016-09-12 09:53:20 -04:00
Jacob Hoffman-Andrews b0c4eef722 Remove obsolete TLS field from challenge model. (#2166) 2016-09-09 15:17:45 -04:00
Roland Bracewell Shoemaker e187c92715 Add gRPC client side metrics (#2151)
Fixes #1880.

Updates google.golang.org/grpc and github.com/jmhodges/clock, both test suites pass. A few of the gRPC interfaces changed so this also fixes those breakages.
2016-09-09 15:17:36 -04:00
Jacob Hoffman-Andrews d75a44baa0 Remove "network" and "server" from syslog configs. (#2159)
We removed these from the config object because we never use anything other than
the default empty string, which means "local socket."
2016-09-08 10:08:18 -04:00
Jacob Hoffman-Andrews 6f3d078414 Allow account deactivation (#2138)
Fixes #2011.
2016-09-07 19:36:54 -04:00