Skip to content

confirmedcode/Main

Repository files navigation

Main Server

This is a public Node.js Express server that hosts the API and website. It does all the client-facing non-VPN functionality like creating accounts, managing subscriptions, and hosting client certificates.

Prerequisites

  • Run the Main CloudFormation and all its prerequisites
  • Initialize the database with Admin Server
  • Creating and setting a CURRENT_SOURCE_ID with Admin Server

Authentication

Requires Authentication calls, require a session cookie from the POST /signin endpoint, which takes either email/password or IAP receipt. If you sign in with a new IAP receipt, a user will be created if that receipt has not been used before.

If a session cookie expires or server returns 401, request a new cookie with /signin.

Sign In With Email/Password

Request

POST /signin 
NameTypeDescription
emailstringRequired User email.
passwordstringRequired User password.

Response

Set-Cookie: <Cookie with Expiration Time> 

Sign In With IAP Receipt

If you sign in with a new IAP receipt, a user will be created if that receipt has not been used before.

Request

POST /signin 
NameTypeDescription
authtypestringRequired Must be either ios or android.
authreceiptstringRequired Base64 encoded IAP receipt.
partnerstringPartner campaign for affiliate referrals. Format is [Partner Code]-[Campaign ID], e.g, acme-1. Partner code and campaign ID should both be lowercase. If no campaign ID is provided, campaign will show up as (no campaign).

Response

Set-Cookie: <Cookie with Expiration Time> 

Log Out (Delete Session)

Request

GET /logout 

Response

Redirects to /signin 

Signup

IAP Signup

Doing a POST /signin with IAP receipt will automatically create a user. An IAP-Signup User is automatically assigned a certificate with source ID CURRENT_SOURCE_ID.

Email Signup - Web

Request

GET /signup 
NameTypeDescription
referstringReferral code.

Email Signup

Request

POST /signup 
NameTypeDescription
emailstringRequired Email to use to create the user.
passwordstringRequired User password. Minimum 8 characters, maximum 50 characters.
browserbooleanWhether or not this request is made from a browser, instead of an API call. If true, after confirming email, user will be redirected to /signin. If false, confirming email will open tunnels://emailconfirmed to complete signup. Defaults to false.
referstringReferral code.

Response

Sends a confirmation email to the user to verify they own the email, with a link to /confirm-email.

If browser == true

Redirect to /signup-success

If browser == false

{code: 1, message: "Email Confirmation Sent" } 

Email Signup Success - Web

Asks user to check their email for a confirmation link.

Request

GET /signup-success 

Confirm Email

A user that confirmes their email is assigned a certificate with source ID CURRENT_SOURCE_ID.

Request

GET /confirm-email 
NameTypeDescription
emailstringRequired Email to confirm.
codestringRequired Code that confirms a user is the owner of an email address to complete email signup.
browserbooleanWhether or not /signup was done by browser or API. If true, redirects to /signin. If false, opens tunnels://emailconfirmed. Defaults to false.

Response

Redirect to either /account or tunnels://emailconfirmed 

Resend Confirmation Email - Web

Request

GET /resend-confirm-code 

Resend Confirmation Email

Request

POST /resend-confirm-code 
NameTypeDescription
emailstringRequired Email to resend confirmation code to.

Response

Redirect to /signin 

Add Email/Password to IAP-Created User

Request

Authentication Required

POST /convert-shadow-user 
NameTypeDescription
newemailstringRequired Email to add to this user.
newpasswordstringRequired Password to add to this user.

Response

Sends a confirmation email to the user to verify they own the email, with a link to /confirm-email.

{code: 1, message: "Email Confirmation Sent" } 

Download App

Webpage With Links to Apps

Request

GET /clients 

Download Mac App

Request

GET /download-mac-app 

Response

Redirects to download the Mac app. If multiple versions are being distributed, the version that this redirects to will be selected randomly at percentages configured by the Admin Dashboard.

Download Mac Update

Request

GET /download-mac-update 

Response

Redirects to download the Mac update file. If multiple versions are being distributed, the version that this redirects to will be selected randomly at percentages configured by the Admin Dashboard.

Download Windows App

Request

GET /download-mac-app 

Response

Redirects to download the Windows app. If multiple versions are being distributed, the version that this redirects to will be selected randomly at percentages configured by the Admin Dashboard.

Download Windows Update

Request

GET /download-windows-update 

Response

Redirects to download the Windows update file. If multiple versions are being distributed, the version that this redirects to will be selected randomly at percentages configured by the Admin Dashboard.

Get User Certificate/Key

Request

Authentication Required

POST /get-key 
NameTypeDescription
platformstringRequired Must be ios, android, windows, or mac

Response

{id: <User ID>, b64: Base64 encoded client certificate } 

Account Management

Account - Web

Request

Authentication Required

GET /account 

Change Email - Web

Request

Authentication Required

Returns CSRF Token

GET /change-email 

Change Email

Request

Authentication Required

CSRF Token Required

POST /change-email 
NameTypeDescription
_csrfstringRequired CSRF Token from GET /change-email
currentPasswordstringRequired User's current password.
newEmailstringRequired User's new email.

Response

Redirect to /account Sends email to confirm 

Change Password - Web

Request

Authentication Required

Returns CSRF Token

GET /change-password 

Change Password

Request

Authentication Required

CSRF Token Required

POST /change-password 
NameTypeDescription
_csrfstringRequired CSRF Token from GET /change-password
currentPasswordstringRequired User's current password.
newPasswordstringRequired User's new password. Must be minimum 8 characters long, maximum 50 characters long.

Response

Redirect to /account 

Invoice History - Web

Request

Authentication Required

GET /invoices 

Get Invoice - Web

Request

Authentication Required

GET /invoices 
NameTypeDescription
idstringRequired The ID of the invoice.

Payment Methods - Web

Request

Authentication Required

GET /payment-methods 

New Payment Method - Web

Request

Authentication Required

GET /add-new-card 

New Payment Method

Request

Authentication Required

POST /add-new-card 
NameTypeDescription
sourcestringRequired Source ID returned from Stripe after user submits their card information.

Response

Redirect to /payment-methods 

Set Default Payment Method

Request

Authentication Required

POST /set-default-card 
NameTypeDescription
cardIdstringRequired Stripe cardID for the payment method to set as default.

Response

{message: "New default set successfully" } 

Delete Payment Method

Request

Authentication Required

POST /delete-card 
NameTypeDescription
cardIdstringRequired Stripe cardID for the payment method to delete.

Response

{message: "Card deleted successfully" } 

Email Opt Out - Web

Links to opt out of email are automatically generated on every email sent to users, and placed at the bottom of every email. Authentication is not required to opt-out of emails, because someone may receive

Request

GET /do-not-email 
NameTypeDescription
emailstringRequired Email to opt-out.
codestringRequired Code for opting out of emails.

Email Opt Out

Request

POST /do-not-email 
NameTypeDescription
emailstringRequired Email to opt-out.
codestringRequired Code for opting out of emails.

Response

Redirect to /sign-in with success message 

Reset Password

Request Reset Password - Web

Request

GET /forgot-password 

Request Reset Password

Request

POST /forgot-password 
NameTypeDescription
emailstringRequired User's email to send reset password request to.

Response

Sends a password request email if it exists.

Redirect to /signin 

Reset Password - Web

Request

GET /reset-password 
NameTypeDescription
codestringRequired A reset password code that was generated for one-time use and sent to the user via email.

Reset Password

Request

POST /reset-password 
NameTypeDescription
codestringRequired A reset password code that was generated for one-time use and sent to the user via email.
newPasswordstringRequired The new password for the user. Minimum 8 characters, maximum 50 characters.

Response

Redirect to /signin 

Subscription Management

Get Subscriptions

Request

Authentication Required

POST /subscriptions 

Response

[{"planType": "all-monthly", "receiptId": "GPA.3353-4716-1949-52255", "expirationDate": "2018-03-10T07:14:06.065Z", "expirationDateString": "March 10, 2018", "expirationDateMs": 1520666046.065, "cancellationDate": null, "cancellationDateString": null, "cancellationDateMs": null, "userId": "a25b8f5640106f9e9a4990e592a3dc4e", "receiptType": "android", "inTrial": false, "renewEnabled": true } ] 

Get Active Subscriptions

Request

Authentication Required

POST /active-subscriptions 

Response

[{"planType": "all-monthly", "receiptId": "GPA.3353-4716-1949-52255", "expirationDate": "2018-03-10T07:14:06.065Z", "expirationDateString": "March 10, 2018", "expirationDateMs": 1520666046.065, "cancellationDate": null, "cancellationDateString": null, "cancellationDateMs": null, "userId": "a25b8f5640106f9e9a4990e592a3dc4e", "receiptType": "android", "inTrial": false, "renewEnabled": true } ] 

New Pro Subscription - Web

This is used by both browser and Mac/PC clients in a webview to create a new Pro subscription via Stripe. Creating subscriptions on iOS/Android clients don't use this because that's handled by iTunes and Google Play.

Request

Authentication Required

GET /new-subscription 
NameTypeDescription
upgradestringCan be ios/android-monthly, ios/android-annual, or not specified. If user is upgrading from an ios or android only plan, redirect them to instructions on how to cancel their iOS/Android subscription after they complete this new subscription signup. No default value.
browserbooleanShows top logo and navigation bar if true. Mac/PC clients using a webview should use false. Defaults to false.
planstringThe plan to subscribe to. Can be all-monthly or all-annual. Defaults to all-monthly.
localestringLocale of user's machine, used for displaying expected currency to pay in, and recorded to Stripe as per legal requirements. User is not guaranteed to pay in this currency - actual payment currency will be based on the country of the credit card. Defaults to en-US.
sourcestringUsed for Stripe's 3D Secure verification
client_secretstringUsed for Stripe's 3D Secure verification

Response

If user already has an active Pro subscription

Redirect to /account with "You already have a Pro subscription" 

If user doesn't have an active Pro subscription

Render new subscription page using locale and existing payment methods, if any. 

New Pro Subscription

Request

Authentication Required

POST /new-subscription 
NameTypeDescription
sourcestringRequired Source ID of a payment method either created by the frontend, or existing on the Stripe customer.
is3dsbooleanWhether or not the source is a newly created 3D Secure payment method. If it is, then a trial is not allowed. Also, we create a charge instead of invoice for the first month/year, then create a subscription plan with that duration as the "trial". Defaults to `false'.
trialbooleanRequired Whether or not to request a trial period. If a user has already had a previous subscription, the server will return an error if another trial is requested.
planstringRequired The plan to subscribe to. Can be all-monthly or all-annual.
upgradestringCan be ios/android-monthly, ios/android-annual, or not specified. If user is upgrading from an ios or android only plan, redirect them to instructions on how to cancel their iOS/Android subscription after they complete this new subscription signup. No default.
browserbooleanIf true, success redirects to /clients. If false, success redirects to tunnels://stripesuccess. Defaults to false.

Response

If upgrade specified

Redirect to /account with message: Be sure to cancel your iOS/Android-only subscription with Apple iTunes/Google Play 

Else if browser == true

Redirect to /clients 

Else

Redirect to tunnels://stripesuccess 

Cancel Subscription - Web

Request

Authentication Required

GET /cancel-subscription 
NameTypeDescription
receiptIdstringRequired Receipt ID of the subscription to cancel.
receiptTypestringRequired Receipt type of the subscription to cancel. Can be android, ios, or stripe.

Response

If receiptType == ios/android

Redirect to /account with message: Subscriptions made through the iOS/Android app must be cancelled through Apple/Google Play 

Else

Render cancel-subscription view with receiptId 

Cancel Pro Subscription

Request

Authentication Required

POST /cancel-subscription 
NameTypeDescription
receiptIdstringRequired Receipt ID of the Pro subscription to cancel.
reasonstringThe reason a user is cancelling their subscription.

Response

Redirect to /account. 

Diagnostic/Other APIs

Test Error Logging

Request

GET /error-test 

Health Check

Request

GET /health 

Response

Status 200{message: "OK from www." + DOMAIN } 

Get Current IP

Request

GET /ip 

Response

Status 200{ip: 12.34.56.78 } 

Speed Test Bucket

Request

GET /download-speed-test 

Response

Speed test files will be accessible by the following format, which allows for faster transfers: https://<bucket>.s3-accelerate.amazonaws.com/<filename>

Status 200{bucket: confirmedvpn-speedtest-bucket } 

Error Responses

Responses with status code 500 will show Unknown Error to user/client and will alert you by email at admin@[domain] or team@[domain].

2XX - Success with Message 4XX - Client Error 429 - Too Many Requests 5XX - Server Error 

Response Format

JSON response with code (see Error Codes) and message. 500 status code errors are server errors which aren't exposed to the client and show a code of -1.

{code: 2, message: "Some error message, like Password Too Short" } 

Too Many Requests

If a client calls an API too frequently, the server will respond with status code 429 and a JSON body of:

{code: 999, message: "Too many requests in this time frame.", nextValidRequestDate: [Date of next valid request], nextValidRequestDateHuman: [Human readable date of next valid request] } 

Error Reference

Status CodeError CodeMessage
500-1Internal server error
2001Email not confirmed
2006No active subscriptions
20062Renewer - Invalid purchase token
200995Renewer - Apple iTunes non-retryable error
4012Incorrect Login, Session Expired/Invalid, or No Such User
4003Request field validation error (e.g, Password too short, etc)
4005Missing receipt in receipt request
4009Invalid iOS IAP receipt
40010Error on response from Apple for receipt verification
40011Invalid IAP receipt type
40018No such confirmation code
40026Error getting subscription - no such subscription
40029Already had a trial, not allowing another
40031Error deleting user
40038Request Mac/Windows but no Pro subscription
40040Email already registered
40048Cannot convert shadow user that already has a confirmed email
40049Unrecognized product ID from iOS IAP receipt
40051Requested Android but no Android/Pro subscription
40052Requested iOS but no iOS/Pro subscription
40057Can't use iOS/Android test suite receipt outside of test suite
40059No such email
40060Email already confirmed
40063Android receipt does not match its signature
40064Android purchase failed on client side with Response code
40065Unable to decode Android base64 receipt sent from client
40066Missing field in android receipt
40067Android payment not received - still pending
40068Invalid android productId
40069OrderId in client receipt and Google verified receipt do not match
40077Error setting new user password: Invalid reset code
40081Can't delete default payment method
40082Can't delete last payment method
40089Wrong email or code for email opt-out
40099Admin - source ID already exists, choose new one
400108Error adding payment method card
400109Error setting default payment method card
400110Can't change email on a user that doesn't have a confirmed email
400125Referral code doesn't exist
429999Too many requests

Feedback

If you have any questions, concerns, or other feedback, please let us know any feedback in Github issues or by e-mail.

We also have a bug bounty program -- please email engineering@confirmedvpn.com for details.

License

This project is licensed under the GPL License - see the LICENSE.md file for details

Contact

engineering@confirmedvpn.com

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •