Commit Graph

118 Commits

Author SHA1 Message Date
Daniel McCarney 7bb16ff21e ACMEv2: Add pending order reuse (#3290)
This commit adds pending order reuse. Subsequent to this commit multiple
add-order requests from the same account ID for the same set of order
names will result in only one order being created. Orders are only
reused while they are not expired. Finalized orders will not be reused
for subsequent new-order requests allowing for duplicate order issuance.

Note that this is a second level of reuse, building on the pending
authorization reuse that's done between separate orders already.

To efficiently find an appropriate order ID given a set of names,
a registration ID, and the current time a new orderFqdnSets table is
added with appropriate indexes and foreign keys.

Resolves #3258
2018-01-02 13:27:16 -08:00
Daniel McCarney 2f263f8ed5 ACME v2 Finalize order support (#3169)
This PR implements order finalization for the ACME v2 API.

In broad strokes this means:

* Removing the CSR from order objects & the new-order flow
* Adding identifiers to the order object & new-order
* Providing a finalization URL as part of orders returned by new-order
* Adding support to the WFE's Order endpoint to receive finalization POST requests with a CSR
* Updating the RA to accept finalization requests and to ensure orders are fully validated before issuance can proceed
* Updating the SA to allow finding order authorizations & updating orders.
* Updating the CA to accept an Order ID to log when issuing a certificate corresponding to an order object

Resolves #3123
2017-11-01 12:39:44 -07:00
Kleber Correia 2fb247488f Consolidate registration model (#3064)
* Consolidate registration model

* Use regModel instead of empty interface
2017-09-12 12:35:40 -04:00
Kleber Correia 02864c11bf Remove AllowAccountDeactivation flag (#2927)
Part of #2712
2017-09-06 11:11:40 -07:00
Roland Bracewell Shoemaker 90ba766af9 Add NewOrder RPCs + methods to SA and RA (#2907)
Fixes #2875, #2900 and #2901.
2017-08-11 14:24:25 -04:00
Roland Bracewell Shoemaker fcef38f78c Performance and cleanup database migration (#2882)
Switch certificates and certificateStatus to use autoincrement primary keys to avoid performance problems with clustered indexes (fixes #2754).

Remove empty externalCerts and identifierData tables (fixes #2881).

Make progress towards deleting unnecessary LockCol and subscriberApproved fields (#856,  #873) by making them NULLable and not including them in INSERTs and UPDATEs.
2017-07-26 15:18:28 -07:00
Jeff Hodges b88750ede0 remove prefixdb and replace with mysql driver params (#2871)
This uses the mysql driver library's capability to use `SET` to set the system
variables that prefixdb previously was.

Unfortunately, the library doesn't sort the params when making the string, so we
have to do a little munging to TestNewDbMap.

Ran it in a checkout of the repo since godeps now doesn't include the test files (which is great!).

```
MYSQL_TEST_ADDR=127.0.0.1:3306 go test .
ok  	github.com/go-sql-driver/mysql	46.099s
```
2017-07-17 16:40:56 -07:00
Roland Bracewell Shoemaker b38077e02e Change prefixdb semantics (#2674)
Instead of executing the prefix for every statement only do it when creating the connection.
Leaves most of the existing naming conventions alone but updates the relevant comments
to reflect setting variables is now connection level instead of statement.

Fixes #2673.
2017-04-12 21:57:58 -07:00
Roland Bracewell Shoemaker 8a1adbdc9a Switch to gorp.v2 (#2598)
Switch from `gorp.v1` to `gorp.v2`. Removes `vendor/gopkg.in/gorp.v1` and vendors `vendor/gopkg/go-gorp/gorp.v2`, all tests pass.

Changes between `v1.7.1` and `v2.0.0`: c87af80f3c...4deece6103

Fixes #2490.
2017-03-08 12:20:22 -05:00
Daniel McCarney fcf361c327 Remove CertStatusOptimizationsMigrated Feature Flag & Assoc. Cruft (#2561)
The NotAfter and IsExpired fields on the certificateStatus table
have been migrated in staging & production. Similarly the
CertStatusOptimizationsMigrated feature flag has been turned on after
a successful backfill operation. We have confirmed the optimization is
working as expected and can now clean out the duplicated v1 and v2
models, and the feature flag branching. The notafter-backfill command
is no longer useful and so this commit also cleans it out of the repo.

Note: Some unit tests were sidestepping the SA and inserting
certificateStatus rows explicitly. These tests had to be updated to
set the NotAfter field in order for the queries used by the
ocsp-updater and the expiration-mailer to perform the way the tests
originally expected.

Resolves #2530
2017-02-16 11:35:00 -08:00
Daniel 7a8e039542
Renames prefixedDatabase pkg to prefixdb 2016-11-30 16:51:08 -05:00
Daniel ae9eb8b256
Renames prefixed-db to prefixedDatabase 2016-11-30 13:35:31 -05:00
Jacob Hoffman-Andrews 673cc6eaa4 Fix max_statement_time and long_query_time (#2311)
We try to set `max_statement_time` on new database connections so that long queries can be interrupted server side. However, the existing code is broken because of connection pooling. The `SET SESSION max_statement_time=...` gets executed on on connection, but subsequent queries won't necessarily be executed on the same connection.

This changes fixed the problem by introducing an alternate DB driver that wraps the MySQL driver to prefix every query with `SET STATEMENT max_statement_time=...`

This also changes `vars.go` to use the DSN form of a database name instead of the URL form. This allows using it directly in `prefixed_db`'s tests, and this is the direction we're moving all of our database URLs. We previously used a homebrewed URL syntax because it allowed us to extract certain fields and set config options, but now `mysql.Config` serves that need.

Fixes #2251
2016-11-08 09:07:36 -05:00
Jacob Hoffman-Andrews 5f1919b40f Use max_statement_time for timeouts. (#2263)
This means that we get a more useful log message for slow queries, and don't
need to close the MySQL connection. It also means that the query is actually
killed on the MySQL side, rather than just timing out and returning on the
client side.

We set the max_statement_time to 95% of the `readTimeout`.

Also set the `long_query_time` to 80% of the `readTimeout`, so that queries that are
close to timing out will be logged by MySQL's slow query logging.
2016-10-20 10:29:29 -04: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
Jacob Hoffman-Andrews 19da2be7ef Set STRICT_ALL_TABLES when setting up DB (#1890)
Fixes #1202.
2016-06-06 13:48:16 -07:00
Jacob Hoffman-Andrews ba47c61dd6 Remove UpdateOCSP and DeniedCSRs (#1866)
Neither is currently used.

* Remove unused UpdateOCSP method.
* Remove deniedCSRs
* Rename and fix migration.
2016-06-02 12:36:55 -07:00
Roland Bracewell Shoemaker 54573b36ba Remove all stray copyright headers and appends the initial line to LICENSE.txt (#1853) 2016-05-31 12:32:04 -07:00
Kane York fef60a8fd6 Add statsd reporting of current DB connection count (#1805)
* rename, change params, restructure
* I'm wondering how I managed that one
* use a metrics.Scope
* move method to SA, update callers
* rerun goimports
* fix compile error
* revert cmd/shell.go

https://github.com/letsencrypt/boulder/pull/1805
2016-05-12 20:33:23 -07:00
Jacob Hoffman-Andrews b3bc3d8e41 Add a MaxDBConns config parameter. (#1793) 2016-05-09 14:21:15 -07:00
Jacob Hoffman-Andrews e6c17e1717 Switch to new vendor style (#1747)
* Switch to new vendor style.

* Fix metrics generate command.

* Fix miekg/dns types_generate.

* Use generated copies of files.

* Update miekg to latest.

Fixes a problem with `go generate`.

* Set GO15VENDOREXPERIMENT.

* Build in letsencrypt/boulder.

* fix travis more.

* Exclude vendor instead of godeps.

* Replace some ...

* Fix unformatted cmd

* Fix errcheck for vendorexp

* Add GO15VENDOREXPERIMENT to Makefile.

* Temp disable errcheck.

* Restore master fetch.

* Restore errcheck.

* Build with 1.6 also.

* Match statsd.*"

* Skip errcheck unles Go1.6.

* Add other ignorepkg.

* Fix errcheck.

* move errcheck

* Remove go1.6 requirement.

* Put godep-restore with errcheck.

* Remove go1.6 dep.

* Revert master fetch revert.

* Remove -r flag from godep save.

* Set GO15VENDOREXPERIMENT in Dockerfile and remove _worskpace.

* Fix Godep version.
2016-04-18 12:51:36 -07:00
Jacob Hoffman-Andrews ecc04e8e61 Refactor log package (#1717)
- Remove error signatures from log methods. This means fewer places where errcheck will show ignored errors.
- Pull in latest cfssl to be compatible with errorless log messages.
- Reduce the number of message priorities we support to just those we actually use.
- AuditNotice -> AuditInfo
- Remove InfoObject (only one use, switched to Info)
- Remove EmergencyExit and related functions in favor of panic
- Remove SyslogWriter / AuditLogger separate types in favor of a single interface, Logger, that has all the logging methods on it.
- Merge mock log into logger. This allows us to unexport the internals but still override them in the mock.
- Shorten names to be compatible with Go style: New, Set, Get, Logger, NewMock, etc.
- Use a shorter log format for stdout logs.
- Remove "... Starting" log messages. We have better information in the "Versions" message logged at startup.

Motivation: The AuditLogger / SyslogWriter distinction was confusing and exposed internals only necessary for tests. Some components accepted one type and some accepted the other. This made it hard to consistently use mock loggers in tests. Also, the unnecessarily fat interface for AuditLogger made it hard to meaningfully mock out.
2016-04-08 16:12:20 -07:00
Jacob Hoffman-Andrews 39d0240793 Remove SQLDebug config option.
It's now the default in all cases that it was configurable. When we want to
suppress SQL debug messages, we can simply adjust the logging level to suppress
debug messages in general.

Also, pass a logger to SetSQLDebug rather than calling GetAuditLogger.
2016-03-29 23:32:02 -07:00
Jacob Hoffman-Andrews 91c95abd19 Clean up logging bugs.
boulder-ca was redundantly calling SetAuditLogger, leading to a warning message.

NewDbMap was calling GetAuditLogger, which is an anti-pattern, but didn't really
need to log anyhow. So deleted those lines. This cleans up some of the spam that
shows up when a test fails.
2016-03-26 19:32:32 -07:00
Kane York f440380330 sa: use mysql.Config to set flags on connect strings
This also exposes an interface to open a connection using a
mysql.Config, so we can start changing config files to use those.

Part of #1505
2016-02-29 15:38:43 -08:00
Roland Shoemaker 8fb87b7e7f Add exact FQDN set rate limit
Adds a new rate limit, certficatesPerFQDNSet, which counts certificates
with the same set of FQDNS using a table containing the hash of the dNSNames
mapped to a certificate serial. A new method is added to the SA in AddCertificate
to add this hash to the fqdnSets table, which is gated by a config bool.
2016-02-19 15:58:07 -08:00
Roland Shoemaker 10b6bb5548 Refactor certificate revocation and OCSP generation workflows
* Moves revocation from the CA to the OCSP-Updater, the RA will mark certificates as
  revoked then wait for the OCSP-Updater to create a new (final) revoked response
* Merges the ocspResponses table with the certificateStatus table and only use UPDATES
  to update the OCSP response (vs INSERT-only since this happens quite often and will
  lead to an extremely large table)
2015-10-08 18:55:11 -07:00
Richard Barnes def19e324b Fix golint in ./sa 2015-10-04 21:03:34 -04:00
Jeff Hodges d433062f16 Merge branch 'master' into issued-names-count 2015-10-01 14:19:14 -07:00
Jacob Hoffman-Andrews 322da1f6a1 Remove LockCol from issuedNames.
Also, limit size of reversedName column to 640.
2015-09-30 16:38:36 -07:00
Jacob Hoffman-Andrews f476432449 Store a DB of issued names.
Add counting for issued names within a given time period.

First part of https://github.com/letsencrypt/boulder/issues/864.
2015-09-28 19:37:50 -07:00
Jacob Hoffman-Andrews f9dff78ca2 Enable SQL debug in SA test. 2015-09-28 19:13:03 -07:00
Roland Shoemaker ff6eca7a29 Submit all issued certificates to configured CT logs
Adds a new service, Publisher, which exists to submit issued certificates to various Certificate Transparency logs. Once submitted the Publisher will also parse and store the returned SCT (Signed Certificate Timestamp) receipts that are used to prove inclusion in a specific log in the SA database. A SA migration adds the new SCT receipt table.

The Publisher only exposes one method, SubmitToCT, which is called in a goroutine by ca.IssueCertificate as to not block any other issuance operations. This method will iterate through all of the configured logs attempting to submit the certificate, and any required intermediate certificates, to them. If a submission to a log fails it will be retried the pre-configured number of times and will either use a back-off set in a Retry-After header or a pre-configured back-off between submission attempts.

This changeset is the first of a number of changes ending with serving SCT receipts in OCSP responses and purposefully leaves out the following pieces for follow-up PRs.

* A fake CT server for integration testing
* A external tool to search the database for certificates lacking a full set of SCT receipts
* A method to construct X.509 v3 extensions containing receipts for the OCSP responder
* Returned SCT signature verification (beyond just checking that the signature is of the correct type so we aren't just serving arbitrary binary blobs to clients)

Resolves #95.
2015-09-17 18:11:05 -07:00
Jeff Hodges 4109b8b3e6 rename pending_authz table to pendingAuthorizations 2015-09-04 14:51:52 -07:00
Jeff Hodges ae58e7d488 turn on strict mode for MariaDB
Avoids silently allowing bad things to happen (like mismatched data
types, strings being truncated, etc.).

Ensures that MySQL/MariaDB warnings are treated as errors. This avoids a
number of nasty edge conditions we could wander into. Common things this
discovers includes places where data being sent had a different type
than what is in the schema, strings being truncated, writes of null to a
NOT NULL column, and so on. See
<https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sql-mode-strict>.

MySQL is very funny.

Fixes #623
2015-08-25 13:17:15 -07:00
Jeff Hodges 7b6f2894f7 add goose as the migration tool
This has required some substantive changes to the tests. Where
previously the foreign key constraints did not exist in the tests, now
that we use the actual production schema, they do. This has mostly led
to having to create real Registrations in the sa, ca, and ra tests. Long
term, it would be nice to fake this out better instead of needing a real
sa in the ca and ra tests.

The "goose" being referred to is <https://bitbucket.org/liamstask/goose>.

Database migrations are stored in a _db directory inside the relevant
owner service (namely, ca/_db, and sa/_db, today).

An example of migrating up with goose:

    goose -path ./sa/_db -env test up

An example of creating a new migration with goose:

    goose -path ./sa/_db -env test create NameOfNewMigration sql

Notice the "sql" at the end. It would be easier for us to manage sql
migrations. I would like us to stick to only them. In case we do use Go
migrations in the future, the underscore at the beginning of "_db" will
at least prevent build errors when using "..." with goose-created Go
files. Goose-created Go migrations do not compile with the go tool but
only with goose.

Fixes #111
Unblocks #623
2015-08-25 12:02:31 -07:00
Roland Shoemaker a28ffbecf6 Merge branch 'master' into challenge-table 2015-08-20 20:33:24 -07:00
Jacob Hoffman-Andrews 56cbe1cc94 Merge pull request #644 from letsencrypt/sql_logger_cleanup
correct the SQLLogger Printf
2015-08-20 18:47:27 -07:00
Jeff Hodges b06ada1e6b correct the SQLLogger Printf 2015-08-20 18:13:38 -07:00
Jeff Hodges 20ad6a8a30 use URL.EscapedPath now that we are on Go 1.5
Plus fix a typo in a comment
2015-08-20 16:10:56 -07:00
Roland Shoemaker 69edf779b5 Switch to real model vs. view 2015-08-18 16:38:06 -07:00
Roland Shoemaker 3fe109d33c Merge master 2015-08-15 16:03:01 -07:00
Jeff Hodges 5e97aa23c6 use MariaDB in the unit tests
And delete the uses of sqlite3
2015-08-14 17:13:15 -07:00
Roland Shoemaker a01a15df07 Switch to challengeModel instead of core.Challenge, various scehma fiddling and trickery 2015-08-14 16:08:46 -07:00
Roland Shoemaker 5601581aec Merge branch 'master' into challenge-table 2015-08-14 13:53:20 -07:00
Jeff Hodges ae5fa728ea always set parseTime to true
There's no reason to not just enforce it in the code completely and not
worry about it elsewhere. If we need to extract code out of NewDbMap,
we'd need recombineURLForDB in it, anyhow.
2015-08-13 22:45:33 -07:00
Roland Shoemaker 5be6e588ee Initial work 2015-08-13 20:24:25 -07:00
Jacob Hoffman-Andrews 64987a3639 Merge pull request #599 from letsencrypt/mysql
use MariaDB in integration tests and start.py
2015-08-11 20:31:46 -07:00
Jeff Hodges 86390e312b require mysql+tcp:// as the scheme for db conns 2015-08-11 20:17:35 -07:00
Jacob Hoffman-Andrews 4d8367bc0e Remove logging of dbConnect string.
This can accidentally put passwords in logs.
2015-08-11 12:32:10 -07:00
Jeff Hodges 7f44d22604 use URL.Path until TravisCI gets 1.5
Either we'll figure out how to get it added or they will.
2015-08-08 02:08:47 -07:00
Jeff Hodges 42a626f9fc fix comment about db URLs and trim dbConnect 2015-08-07 23:30:01 -07:00
Jeff Hodges b08e6e0bad use MariaDB in integration tests and start.py
This changes moves from using SQLite in the integration tests and in the
test/boulder-config.json.

It does not port the unit tests over, unfortunately. That's a much more
invasive change.

This also updates the Dockerfile to include the MariaDB and RabbitMQ
requirements of start.py as well as adjusts the CMD to expose the
boulder server to the host machine. The Dockerfile also needed to have
its Go version bumped and the test.sh had to grow some explict
"function"s.

Updates #132
2015-08-07 23:22:52 -07:00
Jeff Hodges 390464ddf4 correct unique indexing of Registrations
Fixes #579 (which blocks #132).

This changes the SA to use a unique index on the sha256 of a
Registration's JWK's public key data instead of on the full serialized
JSON of the JWK. This corrects multiple problems:

 1. MySQL/Mariadb no longer complain about key's being larger than the
 largest allowed key size in an index
 2. We no longer have to worry about large keys not being seen as unique
 3. We no longer have to worry about the JWK's JSON being serialized with its inner keys in different orders and causing incorrectly empty queries or non-unique writes.

This change also hides the details of how Registrations are stored in
the database from the other services outside of SA. This will give us
greater flexibility if we need to move them to another database, or
change their schema, etc.

Also, adds some tests for NoSuchRegistration in the SA.
2015-08-06 14:19:19 -07:00
Roland Shoemaker df179a1dde Review fixes 2015-07-29 12:17:04 -07:00
Roland Shoemaker ae06aeee30 Move parseTime check to NewDbMap so binaries that don't use a SSA still get the checking 2015-07-27 20:03:20 -07:00
Roland Shoemaker 33a79c3910 Pull out previous parseTime check 2015-07-27 17:57:14 -07:00
Jeff Hodges 79d9b52ad0 rename dbName to dbConnect
The configuration is actually a connection string, not a database name,
and it was a bit confusing.
2015-07-10 16:17:27 -07:00
Richard Barnes 9bd9ed08da Change from adding the parameter to enforcing it 2015-06-23 23:18:45 -07:00
Richard Barnes e7a48127e6 Append ?parseTime=true when needed 2015-06-23 23:01:18 -07:00
J.C. Jones 41f5788c77 Correct most `go lint` warnings. (274 -> 5) 2015-06-16 22:18:28 -05:00
J.C. Jones a8b0e01c5a Finish initial version of OCSP Responder
- Correct the Database implementation to match current schema & GORP
- Add some debug logging
- Correct CA Key identification
- Move SQL Debugging into the Database object and file, so that things that don't use the Storage Authority can toggle it
2015-06-05 15:03:38 -07:00
Roland Shoemaker 573e35ed56 Disallow multiple registrations with same key (and fix all related tests) 2015-06-04 20:21:59 +01:00
Richard Barnes e8edbf5f21 Making capitalization consistent with Go standards 2015-06-01 02:08:47 -04:00
J.C. Jones 4518f0bf17 Migrate CADB to using GORP. 2015-05-28 23:11:03 -07:00
J.C. Jones e14f59c559 Rework from PR #251: 2015-05-28 23:03:48 -07:00
J.C. Jones af0f8446eb Issue #202, Periodic OCSP Signer Tool
- Move dbMap construction and type converter into individual files in the sa package.
- Add DB configuration for the OCSP tool to the boulder config:
  - left to the user if they want to use different boulder-config.json files
    for different purposes.
- Added updater to Makefile
- Fix trailing ',' in the Boulder config, add more panic logging
- Ignore .pem files produced by the integration test
- Change RPC to use per-instance named reply-to queues.
- Finish OCSP Updater logic
- Rework RPC for OCSP to use a transfer object (due to serialization problems of x509.Certificate)
2015-05-27 22:01:29 -07:00