CA Public Certificate Bundle for cURL - php

I have a SSL enabled eCommerce website which uses cURL for payment processing. Everything is running well but recently I learned about "CA Public Certification Bundle for cUrl" that its a good idea to use it for cURL connections.
If this is true than can someone tell me how or how is it better/different than using the standard SSL?
Doesn't the SSL already provide some kind of certification for all connections?

Any HTTPS client connected to an HTTPS server will get its certificate (in fact, it can be a certificate chain). This server certificate must then verified by the client to authenticate the server.
This is normally done by using a number of CA certificates that are configured on the client as trust anchors (i.e. this is what you trust in advance, before encountering the server certificate). The client tries build a chain between the last element of the server chain and one of the CA certificates in its trust anchors. If there is such a valid chain the server certificate is trusted.
A "CA certificate bundle" would be a set of trust anchors. You can build your own by looking for CAs you're willing to trust, or you can use an existing bundle. Most OSes or browser come with an existing bundle. cURL in itself doesn't but it can rely on a pre-defined location (set at compile time) or it also suggests to use the Firefox bundle (via a conversion mechanism). (You can override default setting via extra options, on the command line or via the API.)
Certificate Pinning (which you also mention) has nothing to do with a CA cert bundle. In fact, it's almost the opposite. Instead of relying on 3rd party trust anchors (the certification authorities), you explicitly "pin" a set of server certificates you know as directly trusted. They're not used to verify other certificates, instead, you compare the certificate you get with the exact certificate you're expecting for that host (or at least you compare public keys). This is more like having a reference mapping from server name to certificate (or to public key) and comparing what you get from that host with the reference you have. Of course, this can only work for a reasonably small set of certificates in practice, unlike the CA (PKI) approach which is designed to let you authenticate parties you have never encountered before (via a 3rd party: the CA).
How is it better/different than using the standard SSL?
Doesn't the SSL already provide some kind of certification for all connections?
Using a CA certificate bundle isn't different than using "standard SSL", it is what's commonly used for SSL/TLS connections. You often don't see it because that CA bundle is often supplied with your client (or with the OS).
Note that strictly speaking, this is orthogonal to SSL/TLS itself, which mainly just says you should authenticate the server. Certificate verification (the PKI way, via CA certificates) is defined in a different specification, also complemented by a specification on how to verify the name in the certificate (and the HTTPS specification of course).

Found a great answer here. The comment above really helped. The exact keyword I was looking for was "Certificate Pinning".

Related

Dealing with self-signed SSL certificates

I deal a lot with self-signed SSL certificates as I deploy the systems in offline environments. The problem is that for example Chrome users has to deal with "dangerous site errors" etc, also if I want to even use GuzzleHttp library for connecting to any other service I have to setting secure to none. What's the best way to deal with it?
If you have a Selfsigned certificate this can be made trusted to the specific system that you use. If others from your office uses it then they may need to add this Selfsigned certificate as trusted by adding it to their system certificate store to make this trusted.
When it comes to office environment it is better to contact the Administrator and add the certificate to all the systems (certlm.msc in run for local machine / certmgr.msc for current user) so your colleagues won't get this dangerous site errors.

Authenticate Web Browser with SSL certificate

Is it possible to authenticate a web browser using an ssl certificate.
Say i store a private key in my application, is there any way to read a key from a browser and try to authenticate based on that?
You can authenticate a browser/user using SSL/TLS client-certificate authentication.
The client certificate must be requested by the server, so you'd need access to the server configuration (not just installing some PHP code on a shared server). This is done at the SSL/TLS layer (in fact, the mechanism is not specific to HTTPS): the server requests the client-certificate during the SSL/TLS handshake (sometimes via a renegotiated handshake). In Apache Httpd, this is typically done via SSLVerifyClient (although you'll need to specify other options too).
The server will then verify the certificate against the CAs you've configured it with (possibly your own, and possibly independent of the CAs used for the server certificate itself). (Alternatively, you could disable certificate verification at the server level in some cases, and have the PHP application do it, but this is a bit more advanced and you'd need to know what you're doing.)
You can access the client certificate from your application and obtains its Subject DN (or alternative names), to identify the client.
It's not clear whether you're after identifying a browser or a user. In the end, everything goes through the browser anyway, but client certificates tend to be allocated to users. Users would have to install that certificate into their browser.
EDIT: For further details, it would help if you could clarify your question and what you intend to do with this.
Is it possible to authenticate a web browser using an ssl certificate.
Say i store a private key in my application, is there any way to read
a key from a browser and try to authenticate based on that?
Firstly, strictly speaking, there's no such thing as an "SSL certificate", since multiple types of certificates can be used for SSL/TLS, and some of these same certificates can also be used for other purposes than SSL/TLS. Typically, "SSL certificate" means "X.509 certificate in the context of SSL/TLS".
Therefore, authenticating a web browser using an SSL certificate implies doing it at the SSL/TLS layer. (There have been attempts to implement message-level security using X.509 certificates at the HTTP layer, but they're not widely supported by browsers.)
Secondly, the private key is held by the remote party that you authenticate. The local party that authenticates the remote party doesn't see any private key. If you (as a server) want to authenticate a web browser, it's the browser that needs to have the private key, not your (presumably PHP) application. In this context, it's not quite clear why your (PHP?) application would have/need a private key if it's the browser that you want to authenticate.
What your verifying application may need (if it's not done by the server itself) is a CA certificate to be able to verify the client certificate it is presented with (or at least some form of trust anchors with which to verify the client certificate). There's no private key required here, just public keys and certificates, unless you want your application to be a CA too.
Indeed, you could have your application be a mini CA. It could make the browser generate a key-pair and send a certificate request to the server (there are mechanisms to have a web page make the browser do all that). Then the server would generate the certificate and make the browser import it back against its private key. Subsequently, the browser could use this certificate for authentication with that server (or other servers that would recognise these certificates).
No, you cannot do that.
There is some development going on, and a few day ago W3C has made a proposal for a encryption standard.
You can however put a key in a cookie and use that to identify. This is the default PHP session id behavior.

How does SSL support in PHP PDO (MySQL) work?

I'm familiar with the public/private key negotiation implemented in HTTPS, which is why I am confused by the following driver options that are apparently available (though not officially documented) for PDO's MySQL driver:
PDO::MYSQL_ATTR_SSL_KEY
PDO::MYSQL_ATTR_SSL_CERT
PDO::MYSQL_ATTR_SSL_CA
The link suggests they point to files stored locally - yet why would a copy of anything besides the CA certificate be stored on the client? Has anyone successfully made an encrypted connection using this method?
This pertains to client certificates that the client must have in order to be able to connect to the server, i.e. that the client must verify its identity (yes, SSL can work the other way around as well). Start by reading the general section Using SSL for Secure Connections, then see the REQUIRE clauses in the GRANT syntax:
REQUIRE X509 means that the client must have a valid certificate but that the exact certificate, issuer, and subject do not matter. The only requirement is that it should be possible to verify its signature with one of the CA certificates.
REQUIRE ISSUER 'issuer' places the restriction on connection attempts that the client must present a valid X509 certificate issued by CA 'issuer'. If the client presents a certificate that is valid but has a different issuer, the server rejects the connection. Use of X509 certificates always implies encryption, so the SSL option is unnecessary in this case.
...

Sending signed emails using PHP

What I would like to achieve is being able to send signed emails so that users' email clients show such mails as trusted (e.g. in Thunderbird sometimes such emails are marked with a closed envelope icon).
I found a PHPMailer library which is supposed to send signed emails, but I think it just wraps the openssl_pkcs7_sign PHP function. I am not sure what are and how to get and use keys and certificates which are function's arguments. There are to parameters: $signcert and $privkey. From what I understand the $signcert should be publicly known certificate used to verify that the message was properly signed. The $privkey is something coupled with the certificate, should be kept in secret and is used to sign emails. Am I correct so far?
My problem is how to get proper certificates. I think OpenSSL allows me to generate my own certs, but are such certs sufficient enough for my needs? If they are, how do I generate them properly? I mean there might be certificates of different length and other options which might be important and I am unaware of. And by the way, I noticed that "https" self signed certs cause warnings in browsers. Does same thing happen with mails? In that case probably I should buy certificate from trusted cert center. Can you give me an advice which centers I should consider?
I think OpenSSL allows me to generate my own certs, but are such certs sufficient enough for my needs?
We don't know what your needs are.
A certificate on its own is useless for signing of messages. The value comes where that certificate is itself (verifiably) authenticated by a third party acceptable to both the the sender and resipient. This 3rd party is the Certification Authority (e.g. Thawte, Verisign etc) although within an organisation it may be sufficient to provide your own CA. The OpenSSL documents explain in detail how to create your own CA certificaet which you can use to sign other certificates.
You've got a long learning journey ahead of you before you'll be able to implement any code - you could do worse than start with the openssl howto and x509 cerificates howto.
Here [1] it is implied that the certificate used to sign emails must be issued by Certification Authority (so the email client won't give any warnings). The list of some Authorities which issue free certificates can be found here: [2]. The one I have chosen gives the certificate by installing it directly to a web browser. So to do something more, it should be exported. Popular format is *.p12, which can store both public and private key. But it seems that using PHP function openssl_pkcs7_sign() and pointing it's arguments to the file with both certificates doesn't work - OpenSSL returns ambigous error error:0906D06C:PEM routines:PEM_read_bio:no start line. After separating keys (using OpenSSL) signing works fine.
By the way, even though the PHPMailer is supposed to be capable of singing emails, it's current version doesn't work. Mail is being signed, stored in a temporary file, the file is deleted and after that the content of the file is send (so the message is empty).
[1] - http://kb.mozillazine.org/Message_security
[2] - http://kb.mozillazine.org/Getting_an_SMIME_certificate

using LDAPS authentication

I am using LDAPS authentication with Open source CMS ez publish. I have made all the configuration settings that I am suppoed to make. But, I still cannot get LDAPS authentication to work!
on debugging, I found that ldap_connect fails and it returns resourse id #80 or resource id #75 sometimes. Is there any documentation that describes what these resource ids mean? Even the php documentation of ldap_connect doesn't have any information on these resource ids. Or is there some thing else that I could have done wrong?
The PHP manual on resources. Seems like ldap_connect() is successful. If it fails, it returns FALSE.
The most common SSL related issue is trusting the certificate used in the connection.
If your LDAP servers SSL cert is not signed by a well known CA, or more correctly, by a CA known to your SSL library then it usually will fail. To resolve this you have to make your SSL library trust the CA.
Windows (IE), Firefox, Safari, etc all have their own keystore mechanisms and you can import certificates of the CA's Trusted Root into them. Then all certificates signed by that CA are now trustworthy.
Java uses JKS keystore files, old Netscape uses cert.db7 or cert.db8 files. No clue what PHP uses, however you ought to figure that aspect out.

Categories