 		userConfig.version = version
 		return request(
 			method: 'POST'
-			url: url.resolve(config.apiEndpoint, 'associate')
+			url: url.resolve(config.apiEndpoint, 'sign_certificate?apikey=' + userConfig.apiKey)
 			json: userConfig
 		)
 	.spread (response, body) ->

csrgen = Promise.promisify require 'csr-gen'
request = Promise.promisify require 'request'

module.exports = ->
	# Load config file
	userConfig = require('/boot/config.json')

	version = utils.getSupervisorVersion()

	# I'd be nice if the UUID matched the output of a SHA-256 function, but although the length limit of the CN
	# attribute in a X.509 certificate is 64 chars, a 32 byte UUID (64 chars in hex) doesn't pass the certificate
	# validation in OpenVPN This either means that the RFC counts a final NULL byte as part of the CN or that the
	# OpenVPN/OpenSSL implementation has a bug.
	uuid = crypto.pseudoRandomBytes(31).toString('hex')

	# Generate SSL certificate
	keys = csrgen(uuid,
		company: 'Rulemotion Ltd'
		csrName: 'client.csr'
		keyName: 'client.key'
		outputDir: '/data'
		email: 'vpn@resin.io'
		read: true
		country: ''
		city: ''
		state: ''
		division: ''
	)

	Promise.all([keys, version])
	.then ([keys, version]) ->
		console.log('UUID:', uuid)
		console.log('User ID:', userConfig.userId)
		console.log('User:', userConfig.username)

			knex('config').truncate()
			.then ->
				knex('config').insert([
					{ key: 'uuid', value: userConfig.uuid }
					{ key: 'apiKey', value: userConfig.apiKey }
					{ key: 'username', value: userConfig.username }
					{ key: 'userId', value: userConfig.userId }
					{ key: 'version', value: userConfig.version }
				])
			knex('app').truncate()
		])
