Zhixian's Tech Blog

2017-07-12

Using ACMESharp to get SSL certificates from Let’s Encrypt

This blog post is a reminder note to myself on how to use the ACMESharp PowerShell module to get SSL certificates from Let’s Encrypt CA.

Essentially, the usage can be divided into the following phases:

  1. Install ACMESharp PowerShell module
  2. Import ACMESharp PowerShell module
  3. Initial (one-time) setup
  4. Register DNS of certificate
  5. Get “challenge” details (to prove that you are the owner of the domain)
  6. Signal Let’s Encrypt to confirm your challenge answer
  7. Download certificates

Steps 1-3 is only for setting up on a new PC.
Step 2, 4 should be repeated for each domain that you want SSL certificates for.
Steps 2, 5-7 should be repeated whenever you want to get or renew certificate.

1. Install ACMESharp PowerShell module

Install-Module -Name ACMESharp -AllowClobber

2. Import ACMESharp PowerShell module

Import-Module ACMESharp

 

3. Initial (one-time) setup

Initialize-ACMEVault

New-ACMERegistration -Contacts mailto:zhixian@hotmail.com -AcceptTos

4.  Register DNS of certificate

New-ACMEIdentifier -Dns plato.emptool.com -Alias plato_dns

5. Get challenge (to prove that you are the owner of the domain)

Complete-ACMEChallenge plato_dns -ChallengeType http-01 -Handler manual

6. Signal Let’s Encrypt to confirm your challenge answer

Submit-ACMEChallenge plato_dns -ChallengeType http-01
(Update-ACMEIdentifier plato_dns -ChallengeType http-01).Challenges | Where-Object {$_.Type -eq “http-01”}
New-ACMECertificate plato_dns -Generate -Alias plato_cert1
Submit-ACMECertificate plato_cert1
Update-ACMECertificate plato_cert1

7. Download certificates

NGINX

Get-ACMECertificate plato_cert1 -ExportCertificatePEM “C:\src\certs\plato_cert1.crt.pem”
Get-ACMECertificate plato_cert1 -ExportIssuerPEM “C:\src\certs\plato_cert1-issuer.crt.pem”

Add-Content -Value (Get-Content plato_cert1.crt.pem) -Path nginx.plato.emptool.com.pem
Add-Content -Value (Get-Content plato_cert1-issuer.crt.pem) -Path nginx.plato.emptool.com.pem

HAPROXY

ZX: Generating SSL certificates for HAPROXY is similar to NGINX, except it includes a key.

Get-ACMECertificate plato_cert1 -ExportKeyPEM “C:\src\certs\plato_cert1.key.pem”
Get-ACMECertificate plato_cert1 -ExportCertificatePEM “C:\src\certs\plato_cert1.crt.pem”
Get-ACMECertificate plato_cert1 -ExportIssuerPEM “C:\src\certs\plato_cert1-issuer.crt.pem”

Add-Content -Value (Get-Content plato_cert1.crt.pem) -Path haproxy.plato.emptool.com.pem
Add-Content -Value (Get-Content plato_cert1-issuer.crt.pem) -Path haproxy.plato.emptool.com.pem
Add-Content -Value (Get-Content plato_cert1.key.pem) -Path haproxy.plato.emptool.com.pem

 

IIS

Get-ACMECertificate plato_cert1 -ExportPkcs12 “C:\src\certs\iis.plato_cert1.pfx”

 

Advertisements

2015-02-09

done function not called in jQuery AJAX call

Filed under: development, web application development — Tags: , , — Zhixian @ 23:40:02 pm

In jQuery, you can write an AJAX call that is chained to a done function.
Sometimes this function does not get called.

One of things to examine is the response that you are receiving from the server.
If the response is malformed, the done function will not get triggered.

An example of a malformed response:

{ "result" : OK }

Correct reponse (note the presence of quotation marks around OK:

{ "result" : "OK" }

2015-01-10

Can not load type MembershipPasswordAttribute using ASP.NET (Mono)

Filed under: web application development — Tags: , , , — Zhixian @ 08:33:01 am

Note: This blog post does not provide a solution.

Background

Recently, I was trying to build a ASP.NET MVC project using Mono on my Ubuntu machine.
It did not end well.

While building the login page, I got this error message.

Could not load type ‘System.Web.Security.MembershipPasswordAttribute’ from assembly ‘System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.

Error 500 - Google Chrome_201

The offending code is:

test.mvc.web - Views-Home-Index.cshtml - MonoDevelop_202

As it turns PasswordFor is not the only helper extension that will trigger this error.
TextBoxFor have the same issue as well.

Why this happens

As it turns out, the Mono 4.5 that I am using at this time of writing does not have this implemented yet.

You can view here (http://go-mono.com/status/status.aspx?reference=4.5&profile=4.5&assembly=System.Web).

Mono System.Web in 4.5 vs MS.NET 4.5 - Google Chrome_203

Solution

No good solution to this issue currently.

One possible workaround is not to use the HTML Helper extensions.

2014-12-28

How to install Mono on Ubuntu

Filed under: web application development — Tags: , , , , , — Zhixian @ 01:29:12 am

This blog post describes my installation steps to get Mono running on my Ubuntu.

I will write another blog post on testing this installation.

Assumptions

  1. You have Apache HTTP Server installed
  2. You know how to start a terminal session and run commands there.

Summary

  1. Add Mono Project GPG signing key
  2. Add Mono Package Repository
  3. Add mod_mono Repository
  4. Update package cache
  5. Install Mono
  6. Install mod_mono
  7. Enable mod_mono
  8. Reference

Mono Project GPG signing key

This step adds the GPG signing key to your key-ring.
This signing key is used to make sure the installed files are valid.
To add the key to your key ring, start a terminal session and run the following command:

sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

zhixian@SARA: ~_120

Add Mono Package Repository

This step add the Mono package repository into apt-get list of available package repositories.
Enter the following command at the command-line of the terminal session:

echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list

zhixian@SARA: ~_121

Add mod_mono Repository

This step adds the repository for mod_mono to apt-get list of available package repositories.
mod_mono is use by Apache HTTP server to interpret .NET web pages.
To add the repository, run the following command at the command-line:

echo “deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main” | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list

zhixian@SARA: ~_124

Update package cache

To update the apt-get package cache to use the repositories that you just added, run the following command at the command-line:

apt-get update

zhixian@SARA: ~_125

Install Mono

To install the complete Mono package enter the following at the command-line:

sudo apt-get install mono-complete

zhixian@SARA: ~_126

After the initial listing of the packages that will be installed, you will be given a prompt asking if you would like to proceed install Mono. Enter “Y” to proceed with the installation process.

zhixian@SARA: ~_127

zhixian@SARA: ~_128

Install mod_mono

Run the following command to add mod_mono:

sudo apt-get install libapache2-mod-mono

zhixian@SARA: ~_129

You might see an error exit status at the end of the installation process.
This is due to some configuration issue in the installation process.
I’m not too sure what exactly is the issue but it seems fine to ignore it.

zhixian@SARA: ~_131

Enable mod_mono

mod_mono is enabled by running the following command:

sudo a2enmod mod_mono

zhixian@SARA: ~_133

Reference

http://www.mono-project.com/docs/getting-started/install/linux/

https://help.ubuntu.com/community/ModMono

2014-12-21

Google App Engine development on Ubuntu for Python (Part 2 of 2)

Filed under: web application development — Tags: , , , , , — Zhixian @ 23:46:12 pm

This blog post describes how to run Google App Engine (GAE for short) on Ubuntu.
This is the second part of a 2-part blog post.
This blog post focus on writing a simple (helloworld) application just to demonstrate that the setup works and that we can deploy our application.

Parts

  1. Setting up Google App Engine SDK
  2. Running Google App Engine (this article)

An aside related article, How to Add Google App Engine project to Google Developers Console.

Assumptions

This blog post builds on the previous blog post Setting up Google App Engine SDK and assumes that you have followed the instructions there.

This blog post also assumes you know how to register a Google App Engine project in the Google Developers Console.
If you need help with this, you can take a look at my blog post, How to Add Google App Engine project to Google Developers Console.

Part 2 Summary

  1. Create project folders (opinionated)
  2. Create request handler
  3. Create configuration file
  4. Test project
  5. Deploying project

Create Project Directory

(Opinionated) I usually store my projects in a Projects folder in my home folder.

zhixian_084

Inside this Projects folder, right-click the folder area to display the context menu.
Click Create Folder from the context menu.

zhixian@SARA: ~-Projects_085

Name the folder HelloWorld.
So your Projects folder, should look like the below.
The files (request handler and configuration) will be stored inside the HelloWorld folder that you have created.

Projects_086

Create Request Handler

Double-click the HelloWorld folder to open the folder.
Right-click in the folder area to display the context menu.
Click Empty File from the context menu.

HelloWorld_087

Name the file as

HelloWorld.py

Your HelloWorld folder should look like the below:

HelloWorld_088

Right-click the HelloWorld.py file that you just created to display its context menu.
Click Open with Text Editor from the context menu to edit the file.
This will open the file in your configured text editor. By default, this should be gedit.

HelloWorld_090

Copy and paste the below into the file.

import webapp2

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, World!')

application = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)

After you paste the above content into the file, it should look like the below.
Note the amount of space used for indentation.
This is important in Python as indentation is used to indicate code blocks.

Click on Save on the toolbar to save the file.

HelloWorld.py (~-Projects-HelloWorld) - gedit_092

Create Configuration File

In your HelloWorld folder, right-click in the folder area to display the context menu.
Click Empty File from the context menu.

HelloWorld_093

Name this file

app.yaml

HelloWorld_095

Right-click the app.yaml file that you just created to display its context menu.
Click Open with Text Editor from the context menu to edit the file.

HelloWorld_096

Copy and paste the below into the file, replacing the your-app-id with the project id that you defined in your Google Developers Console.

application: your-app-id
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: HelloWorld.application

Now, you are ready to test the project.

Test Project

To test your project, open a terminal session and go to the folder that holds your project folder.
For my example, my HelloWorld project is created in a folder call Projects in my home folder.
So I would type the following command after starting the terminal session.

cd Projects

If I list the contents of the Projects folder, it should look like the below:

zhixian@SARA: ~-Projects_105

To run the HelloWorld application,

  1. Enter the following at the command prompt:

    dev_appserver.py HelloWorld/

  2. You will be prompt to give permission for the dev_appserver script to check for updates on startup.
    Enter “n” to disallow this check. Leaving this as “Y” or blank will allow dev_appserver to check for updates.
  3. Note the url of the “default” module.
    This is the url that your application is being hosted at.
    By default it is:

    http://localhost:8080

  4. Note the url of the admin server.
    This is the url that of the local testing administration server to your application.
    By default it is:

    http://localhost:8000

zhixian@SARA: ~-Projects_104

If you open your browser and navigate to the url of the “default” module (http://localhost:8080), you should see:

Firefox Developer Edition_107

If you open your browser and navigate to the url of the admin server (http://localhost:8000), you should see:

Instances - Firefox Developer Edition_108

To stop the test server, press <Control>-<C> keys combination.

zhixian@SARA: ~-Projects_109

Deploy Project

To upload the project to Google:

  1. Enter the following command at the command prompt:

    appcfg.py update HelloWorld/

  2. Enter your Google (gmail) account.
  3. Enter the password to your account.
  4. After the update has complete, you should see “Deployment Success”, somewhere near the end.

zhixian@SARA: ~-Projects_110

After you have deployed the application, you can access it at:

http://<project-id>.appspot.com/

Firefox Developer Edition_111

Reference

  1. Hello, World! – Python – Google Cloud Platform
  2. Uploading Your Application – Python – Google Cloud Platform

How to Add Google App Engine project to Google Developers Console

This blog post describes how to create add Google App Engine project.

Assumption

You have a Google account.

Summary

  1. Log in to Google Developers Console
  2. Create Project

Log in to Google Developers Console

In your web browser, navigate to Google Developers Console (https://console.developers.google.com/)

Google Developers Console - Firefox Developer Edition_097

After you logged in, you should be redirected to your project page.

Create Project

Click Create Project to display the new project.

Google Developers Console - Firefox Developer Edition_098

On the New Project dialog, enter:

  1. A name for your project.
    For example, I am naming my hello world project as zx-helloworld.
  2. An id for your project.
    Important This id will be used for the deployment of your project.
    For example, I am naming my hello world id as zx-helloworld.
  3. Click Create to add the project.

Note

The project id needs meet the follow criteria:

  1. Starts with a lower-case letter (a-z)
  2. May contains lower-case letters, digits (0-9) or hyphen (-)

Google Developers Console - Firefox Developer Edition_099

After you clicked Create, the dialog will close.
You should see a small popup at the lower right-hand corner of the page.

Google Developers Console - Firefox Developer Edition_100

The popup should indicate that its creating the project.

Google Developers Console - Firefox Developer Edition_100

After the project is created, it should redirect you to the project dashboard.

Google Developers Console - Firefox Developer Edition_101

The popup in the lower right corner of the page, should have a green checkbox.

Google Developers Console - Firefox Developer Edition_102

With this, your Google App Engine project can be deployed using the project id that you defined.

2014-12-02

How to install PHP to Apache HTTP Server in Ubuntu 14.04 (Trusty Tahr)

Filed under: php, web application development — Tags: , , , , , , — Zhixian @ 10:36:12 am

This blog post describes how I install PHP to Apache HTTP Server and test the installation on my Ubuntu installation.

Steps

  1. Installation
  2. Verifying PHP5 Modules in Apache2 HTTP Folder
  3. Testing installation

Installation

The quick and simple way is to use Ubuntu Software Center (search term: php5).
This will install the latest version of PHP5 available in the Ubuntu Software Center.

Ubuntu Software Center_010

Verifying PHP5 Modules in Apache2 HTTP Folder

After the installation is complete, you should see Apache HTTP modules for PHP in the mods-enabled folder.
By default (if you installed Apache HTTP server via Ubuntu Software Center), the installation folder is located at:

/etc/apache2

In the installation folder, there should be a folder labeled mods-enabled.
In this folder, you should see a php5.conf (that holds your configuration settings for PHP5) and php5.load (the actual Apache2 module for PHP5) file.

zhixian@SARA: -etc-apache2-mods-enabled_011

Testing installation

After you confirmed that PHP module is enabled in PHP, you can test your installation.
To do so, create a test.php file in Apache’s document root folder.
By default, the document root folder is located in /var/www/html.
However, the owner and group access for this folder belongs to the root user.

html Properties_013

This means you need to access the /var/www/html folder as a superuser in order to make changes to the folder.
One way would be start a terminal session and enter the following commands:

gksudo caja /var/www/html &

zhixian@SARA: ~_015

If you are not using Mate desktop, replace “caja” with “nautilus” as in:

gksudo nautilus /var/www/html &

This command can be explained as follows:

gksudo – run command as superuser. This is similar to the sudo command. But because we are running the command in the background (see & below), the prompt to allow us to enter administrator’s credentials will be in the background as well. By using gksudo, we will get a prompt like the below, that allows us to enter administrator’s password.

Workspace 1_016

caja (or nautilus) – command to activate your file manager

/var/www/html – parameter used by file manager. File manager use this parameter and open this folder when it start.

& – The ampersand indicates that this command is to run in the background. If this is missing, the terminal session will be dedicated to run the file manager until the file manager application terminated.

After you run the command, you should see:

html (as superuser)_017

In this folder, create a file call test.php with the following contents:

<html>
<head>
<title>PHP Test Page</title>
</head>
<body>
<h2>A PHP test page</h2>
<?php echo “hello world”; ?>
</body>
</html>

test.php (-var-www-html) - gedit (as superuser)_018

Now, your /var/www/html folder should look something like this:

html (as superuser)_020

Go to your browser and navigate to:

http://localhost/test.php

You should see a result like the below:

PHP Test Page - Google Chrome_021

2014-09-01

Running Classic ASP on IIS in Windows 7

Filed under: web application development — Tags: , , , — Zhixian @ 00:06:09 am

This blog post describes how to enable IIS7 in WIndows 7 to run classic ASP scripts.

Assumptions

This guide assumes:

  1. You know how to go to Windows 7 Control Panel.
  2. You know how to go to Internet Information Services (IIS) Manager

Steps to enabling ASP on IIS

1. In the Control Panel, click the item labeled “Programs and Features”.

image

2. In the Programs and Features window, click on the option “Turn Windows features on or off”.

image

3. In the Windows Features dialog, scroll down until you reach the item “Internet Information Services”.
Click the plus sign next to item label to display the menu items under “Internet Information Services”.
Repeat the same steps for “World WIde Web Services” under “Internet Information Services”.
Repeat again for “Application Development Features” under “World Wide Web Services”.

In the list of items under “Application Development Features”, is “ASP”.
Checked the box next to “ASP”.
Click on the “OK” button to apply changes.

image

After you clicked on the “’OK“ button, Windows will proceed to install the classic ASP extension into IIS.

image

After installation is complete, Windows will return you back to the Programs and Features window.

image

Verify installation

If your Internet Information Services (IIS) Manager happens to be open, close it.
If you open your IIS manager, you should see a menu item labeled ASP at server node.
image

Clicking on this item will allow you to configure settings for your classic ASP runtime.

2014-08-31

ASP.NET HTTP 503

Filed under: web application development — Tags: , , , , , , — Zhixian @ 22:47:08 pm

When working in ASP.NET, your web site that had been working fine might suddenly give you the below screen:

image

You are most likely to be receiving this error message because the application pool had stopped.

image

Your web site should start up again after you start the application pool.

image

Web site after application pool was started.

image

2014-08-09

Undefined function sqlsrv_connect()

One of the issues with using Microsoft Drivers 3.0 for PHP is it only works up to PHP version 5.4 while the latest stable version is 5.5.
Attempting to connect to a Sql Server database using the driver on a PHP 5.5 runtime will result in the following message.

image

Some workarounds would be:

  1. Use ODBC instead of Microsoft Drivers 3.0 for PHP.
  2. Downgrade the your PHP runtime from 5.5 to 5.4
  3. Get the source code for Microsoft Drivers 3.0 for PHP and compiled it for PHP 5.5 runtime.
  4. Get one of the re-compiled Microsoft Drivers 3.0 for PHP for PHP 5.5 that are distributed by others in the Internet.
Older Posts »

Blog at WordPress.com.