Example #1
0
func main() {
	env := service.Env{}
	// Parse the command line arguments
	service.ParseArgs()
	err := service.ReadConfig(&env.Config)
	if err != nil {
		log.Fatalf("Error parsing the config file: %v", err)
	}

	// Open the connection to the local database
	env.DB = service.OpenSysDatabase(env.Config.Driver, env.Config.DataSource)

	// Opening the keypair manager to create the signing database
	env.KeypairDB, err = service.GetKeyStore(env.Config)
	if err != nil {
		log.Fatalf("Error initializing the signing-key database: %v", err)
	}

	var router *mux.Router
	var address string

	switch service.ServiceMode {
	case "admin":
		// Create the admin web service router
		router = service.AdminRouter(&env)
		address = ":8081"
	default:
		// Create the user web service router
		router = service.SigningRouter(&env)
		address = ":8080"
	}

	log.Fatal(http.ListenAndServe(address, router))
}
Example #2
0
func main() {
	env := service.Env{}
	// Parse the command line arguments
	service.ParseArgs()
	service.ReadConfig(&env.Config)

	// Open the connection to the local database
	env.DB = service.OpenSysDatabase(env.Config.Driver, env.Config.DataSource)

	// Create the keypair table, if it does not exist
	err := env.DB.CreateKeypairTable()
	if err != nil {
		log.Fatal(err)
	} else {
		log.Println("Created the 'keypair' table.")

		// Create the test key (if the filesystem store is used)
		if env.Config.KeyStoreType == "filesystem" {
			// Create the test key as it is in the default filesystem keystore
			env.DB.PutKeypair(service.Keypair{AuthorityID: "System", KeyID: "61abf588e52be7a3"})
		}
	}

	// Create the model table, if it does not exist
	err = env.DB.CreateModelTable()
	if err != nil {
		log.Fatal(err)
	} else {
		log.Println("Created the 'model' table.")
	}

	// Create the keypair table, if it does not exist
	err = env.DB.CreateSettingsTable()
	if err != nil {
		log.Fatal(err)
	} else {
		log.Println("Created the 'settings' table.")
	}

	// Create the signinglog table, if it does not exist
	err = env.DB.CreateSigningLogTable()
	if err != nil {
		log.Fatal(err)
	} else {
		log.Println("Created the 'signinglog' table.")
	}

	// Create the nonce table, if it does not exist
	err = env.DB.CreateDeviceNonceTable()
	if err != nil {
		log.Fatal(err)
	} else {
		log.Println("Created the 'nonce' table.")
	}

	// Initalize the TPM store, authenticating with the TPM 2.0 module
	if env.Config.KeyStoreType == service.TPM20Store.Name {
		log.Println("Initialize the TPM2.0 store")
		err = service.TPM2InitializeKeystore(env, nil)
		if err != nil {
			log.Fatal(err)
		} else {
			log.Println("Initialized TPM 2.0 module.")
		}
	}
}