Koozali.org: home of the SME Server

ssl cert virtual domains

Offline crazybob

  • *****
  • 894
  • +0/-0
    • Stalzer R&D
ssl cert virtual domains
« on: May 18, 2010, 02:35:41 AM »
Would it possible to set up certs for virtual domains based on this http://onlamp.com/pub/a/apache/2005/02/17/apacheckbk.html article ?

TAI


Bob
If you think you know whats going on, you obviously have no idea whats going on!

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: ssl cert virtual domains
« Reply #1 on: May 18, 2010, 04:12:36 AM »
Would it possible to set up certs for virtual domains based on this http://onlamp.com/pub/a/apache/2005/02/17/apacheckbk.html article ?

SME server already sets up virtual domains exactly as specified in that article - in the last code block, just before the paragraph "In other words, exactly the way you'd set up regular virtual hosts, except turning on SSL in each one".

Offline crazybob

  • *****
  • 894
  • +0/-0
    • Stalzer R&D
Re: ssl cert virtual domains
« Reply #2 on: May 18, 2010, 12:51:10 PM »
but would it be possible to use a different ssl cert and port as in the first block of code? :-)
If you think you know whats going on, you obviously have no idea whats going on!

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: ssl cert virtual domains
« Reply #3 on: May 18, 2010, 01:20:05 PM »
AFAIR there should be already some posts about your request and a NFR in bugzilla..
please search, thank you :-)

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: ssl cert virtual domains
« Reply #4 on: May 18, 2010, 02:30:41 PM »
but would it be possible to use a different ssl cert and port as in the first block of code? :-)

Yes, you can do that with a custom template.

Offline crazybob

  • *****
  • 894
  • +0/-0
    • Stalzer R&D
Re: ssl cert virtual domains
« Reply #5 on: May 19, 2010, 12:53:10 PM »
I have created templates in the past for httpd, but they always affect all ibays. I have been searching, but I have not been able to find a way to make a template fragment that will affect only a specific ibay/vhost. Looking for a push in the right direction :-)
If you think you know whats going on, you obviously have no idea whats going on!

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: ssl cert virtual domains
« Reply #6 on: May 19, 2010, 03:06:15 PM »
I have created templates in the past for httpd, but they always affect all ibays. I have been searching, but I have not been able to find a way to make a template fragment that will affect only a specific ibay/vhost. Looking for a push in the right direction :-)
Create the proper directory structure in the templates-custom folder and instead of the VirtualHosts folder create the folder with, for instance, the name of your domain.

Copy the relevant fragments from the original VirtualHosts container to the folder for your domain and modify according to your wishes.

Add a property TemplatePath with the name of your domain to the domain in the domains database:

Code: [Select]
db domains setprop domain.tld TemplatePath directoryname
signal-event domain-modify domain.tld

IIRC that is how you can override one domain.
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline crazybob

  • *****
  • 894
  • +0/-0
    • Stalzer R&D
Re: ssl cert virtual domains
« Reply #7 on: May 19, 2010, 05:35:40 PM »
I will give it a try on a test server. Thanks :D
If you think you know whats going on, you obviously have no idea whats going on!

Offline crazybob

  • *****
  • 894
  • +0/-0
    • Stalzer R&D
Re: ssl cert virtual domains
« Reply #8 on: May 23, 2010, 11:09:34 PM »
I created a folder called test in /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/
In the test folder I placed a file called test1 with the following code
Code: [Select]
{
    my $listen_default = "Listen 0.0.0.0:445";

    my $mode = $SystemMode || "serveronly";

    return $listen_default if ($mode eq "serveronly");

    my $httpdAccess = ${'httpd-e-smith'}{access} || 'private';

    return $listen_default unless ($httpdAccess eq "private");

    # Only selectively bind interfaces if we are in private server/gateway mode

    my @ipAddresses = ("127.0.0.1", $LocalIP);

    # Remove any duplicate IP addresses
    my %ipAddresses = map { $_ => 1 } @ipAddresses;
    foreach my $ip (sort keys %ipAddresses)
    {
$OUT .= "Listen $ip:445\n";
    }
}

issued command
Code: [Select]
db domains setprop test.com /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf testfollowed by
Code: [Select]
signal-event domain-modify test.com
Nothing changes in httpd.conf

Edit to replace code in first block
« Last Edit: May 24, 2010, 12:00:45 AM by crazybob »
If you think you know whats going on, you obviously have no idea whats going on!

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: ssl cert virtual domains
« Reply #9 on: May 24, 2010, 12:06:09 AM »
Nothing changes in httpd.conf

What you have done does not match what cactus suggested you do.

Note, however, that if you wish to use the TemplatePath option, then you need to provide a full set of template fragments for domains.

Your code, in any case, does nothing to provide a different port for each virtual domain. All you seem to be trying to do, albiet imperfectly, is use port 445 instead of port 443. That won't achieve what you are trying to achieve.

Offline crazybob

  • *****
  • 894
  • +0/-0
    • Stalzer R&D
Re: ssl cert virtual domains
« Reply #10 on: May 24, 2010, 12:14:52 AM »
Thank you for the reply Charlie. I was hoping to change the ssl port on only one v/domain. The article I referenced at the top of this thread lead me to believe I could use 2 ssl certs if I use different ports. If I copy all the templates, and make the appropriate changes for the port number, and add the ssl cert paths, should that work, or is there an easier way?
If you think you know whats going on, you obviously have no idea whats going on!

Offline crazybob

  • *****
  • 894
  • +0/-0
    • Stalzer R&D
Re: ssl cert virtual domains
« Reply #11 on: May 24, 2010, 02:50:53 AM »
Looking at the contents of the files in the VirtualHost folder, I see nothing to set the ssl port to 445. I do see a series of files in the httpd.conf folder that do address the ssl port. Should I be using those to change the port number?
If you think you know whats going on, you obviously have no idea whats going on!

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: ssl cert virtual domains
« Reply #12 on: May 24, 2010, 10:04:10 AM »
Disclaimer: This might work, I have not tested it.

First create the directory structure needed for the custom-template fragments:
Code: [Select]
mkdir -p /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts/
Copy the original template fragments that need to be customize to the same relative location in the custom-templates tree:

Code: [Select]
cd /etc/e-smith/templates-custom/etc/httpd.conf/httpd/conf/
cp /etc/e-smith/templates/etc/httpd/conf/httpd.conf/80VirtualHosts .
cp /etc/e-smith/templates/etc/httpd/conf/httpd.conf/VirtualHosts/25SSLDirectives VirtualHosts/

If no other custom template fragments are present for httpd.conf your custom-template tree should now look like this:
Code: [Select]
[root@smetest httpd.conf]# ls -R
.:
80VirtualHosts  VirtualHosts

./VirtualHosts:
25SSLDirectives
[root@smetest httpd.conf]#

Now edit the copied fragments with your favorite editor. Let's start with the 80VirtualHosts fragment.

Change the following line:
Code: [Select]
       foreach my $port (qw(80 443))to:
Code: [Select]
       my $sslport = $domain->prop('SSLPort') || '443';

       my @ports = 80;
       push (@ports, $sslport);

       foreach my $port (@ports)
And below this line:
Code: [Select]
                port => $port,add the following line:
Code: [Select]
                sslport => $sslport,Now save this file as you are done with it.

On with the second file (./VirtualHosts/25SSLDirective):
Change the following line:
Code: [Select]
    return "    # skipping SSL directives\n" unless $port eq "443";to
Code: [Select]
    return "    # skipping SSL directives\n" unless $port eq $sslport;Now save this file as you are done with it.

We have now created custom-template fragments that superseed the original template fragments when the configuration file is generated. The template fragment take a additional parameter from the domains database that specifies the SSL port to use for the domain, if none is provided the default port (443) will be used.

To modify the port number for a domain you can add/modify the SSLPort property in the domains database like this:
Code: [Select]
db domains setprop domain.tld SSLPort portnumberMake sure to replace the domain.tld with the domain name you defined in server-manager as well as to set the port number you desire the https domain to be listening on.

After you have defined the port number you need to regenerate the configuration file and restart the web server, this can be done with the following command:
Code: [Select]
signal-event domain-modify
To remove the custom template fragments and restore SME Server's default behavior you just need to remove the custom-template fragments like this:
Code: [Select]
rm /etc/e-smith/templates-custom/etc/httpd.conf/httpd/conf/80VirtualHosts
rm /etc/e-smith/templates-custom/etc/httpd.conf/httpd/conf/VirtualHosts/25SSLDirective
signal-event domain-modify
« Last Edit: May 24, 2010, 10:07:32 AM by cactus »
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline crazybob

  • *****
  • 894
  • +0/-0
    • Stalzer R&D
Re: ssl cert virtual domains
« Reply #13 on: May 24, 2010, 12:20:55 PM »
Thanks Cactus, but it didn't work. The httpd.conf did not change

I will also need to apply paths for the ssl cert and key.
If you think you know whats going on, you obviously have no idea whats going on!

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: ssl cert virtual domains
« Reply #14 on: May 24, 2010, 12:31:26 PM »
Thanks Cactus, but it didn't work.
What did not work? Could you be more explicit? Where there errors present in any of the steps? Did your webserver not start anymore? Where you unable to access certain sites you host? I have no crystal ball.

I will also need to apply paths for the ssl cert and key.
That would be a only little harder as you would need to bring those parameters inside of the VirtualHosts containers and evaluate them based on the domain name as this is, by default, done for the whole server and not on a per VirtualHost based way.

You will most likely need to add a custom template fragment based on the /etc/e-smith/templates/etc/httpd/conf/httpd.conf/35SSL10SSLCertificate* files in the VirtualHosts/ folder and build the logic to get the proper files based on the domain name.
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)