Software Defined Networking
cancel
Showing results for 
Search instead for 
Did you mean: 

HP SDN VAN Controller - V2.0.0.4253 - Token Generation using LIB CURL

 
Highlighted
Occasional Visitor

HP SDN VAN Controller - V2.0.0.4253 - Token Generation using LIB CURL

 

/********************************************************
 Purpoese : Program to generate the token for HP VAN controller
 Library  : libcurl is used
 Usage    : gcc -o token hp_forum_token.c -lcurl

 Reference Command :
     curl -k -X POST  "https://127.0.0.1:8443/sdn/v2.0/auth" -d '{"login":{"user":"sdn","password":"skyline"}}' -H "Content-Type:application/json"

*/

#include <stdio.h>
#include <curl/curl.h>
#include<string.h>
#include<stdlib.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl_global_init(CURL_GLOBAL_DEFAULT);

  curl = curl_easy_init();
  if(curl) {

    struct curl_slist *slist = NULL;
    /* -H Header */
    slist = curl_slist_append(slist, "Content-type: application/json");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);

    /* URL */
    curl_easy_setopt(curl, CURLOPT_URL, "https://127.0.0.1:8443/sdn/v2.0/auth");

    /*  -X POST */
    curl_easy_setopt(curl, CURLOPT_POST, 1L);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "user=sdn&password=skyline&domain=sdn");

 /* -v option */
    curl_easy_setopt(curl,CURLOPT_VERBOSE,1L);

    /* -k option */
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);


    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    /* always cleanup */
    curl_slist_free_all(slist);
    curl_easy_cleanup(curl);
  }

  curl_global_cleanup();

  return 0;
}

 

Hi Team,

 

I installed the HP SDN VAN controller software. I can able to successfuly generate the token using the following curl command as mentioned in HP documentation.

 

"curl -k -X POST  "https://127.0.0.1:8443/sdn/v2.0/auth" -d '{"login":{"user":"sdn","password":"skyline"}}' -H "Content-Type:application/json"

 

As a part of application development using HP SDN VAN Controller, I used libcurl library utility to generate the token. I am facing issues as I could not able to generate the token. I followed all the option setting as mentioned in above curl command. I am not sure whether any other options needs to given to generate the token. The following is the error generated.

 

 

Refer the code as shown above for reference. Any help is appreciated. Thanks for understanding

 

 

================ Error Message ============================

 

 

* About to connect() to 127.0.0.1 port 8443 (#0)
*   Trying 127.0.0.1... * connected
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSL connection using DHE-DSS-AES256-SHA
* Server certificate:
*        subject: C=CA; ST=CA; L=Palo Alto; O=HP; OU=HP SDN Controller; CN=127.0.1.1
*        start date: 2014-04-15 14:22:31 GMT
*        expire date: 2014-07-14 14:22:31 GMT
*        issuer: C=CA; ST=CA; L=Palo Alto; O=HP; OU=HP SDN Controller; CN=127.0.1.1
*        SSL certificate verify result: self signed certificate (18), continuing anyway.
> POST /sdn/v2.0/auth HTTP/1.1
Host: 127.0.0.1:8443
Accept: */*
Content-type: application/json
Content-Length: 36

* upload completely sent off: 36out of 36 bytes
< HTTP/1.1 400 Bad Request
< Server: Apache-Coyote/1.1
< X-FRAME-OPTIONS: deny
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, PUT, HEAD, PATCH
< Access-Control-Allow-Headers: Content-Type, Accept, X-Auth-Token
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Tue, 08 Jul 2014 20:00:50 GMT
< Connection: close
<
* Closing connection #0
{"error":"java.lang.IllegalArgumentException","message":"Unable to parse login data&colon; Unexpected character ('u' (code 117)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: java.io.StringReader@34e34720; line: 1, column:

 

 

==================================================================================

 

 

 

 

 

 

 

 

 

 

 

 

11 REPLIES 11
Highlighted
Trusted Contributor

Re: HP SDN VAN Controller - V2.0.0.4253 - Token Generation using LIB CURL

Hello kaarthik,

 

Please modify below line

curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "user=sdn&password=skyline&domain=sdn"); 

 as

 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{ \"login\": { \"user\": \"sdn\", \"password\": \"skyline\",\"domain\":\"sdn\" }}");

 

and try again.

 

Please let us know if this helps.

 

Thanks,

HP SDN Team

Highlighted
Frequent Advisor

Re: HP SDN VAN Controller - V2.0.0.4253 - Token Generation using LIB CURL

Hi SDN Team,

 

I am not able to get the token, as i am getting the ssl error.

 

Below is the error I am getting.

 

* Hostname was NOT found in DNS cache
* Trying 128.88.150.151...
* Connected to 128.88.150.151 (128.88.150.151) port 8443 (#0)
* unable to use client certificate (no key found or wrong pass phrase?)
* Closing connection 0
curl_easy_perform() failed: Problem with the local SSL certificate

Process returned 0 (0x0) execution time : 2.234 s

OR

 

some time ceft error, and some time ssl connection error.

 

Below is the code  I am using, in a c lang, 

 

curl_easy_setopt(curl, CURLOPT_PROXY, "");
curl_easy_setopt(curl, CURLOPT_SSLKEY, "cacert.pem");
curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE, "PEM");
curl_easy_setopt(curl, CURLOPT_CAINFO, "cacert.pem");
curl_easy_setopt(curl, CURLOPT_SSLCERT, "cacert.pem");

/* -X POST */
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"login\":{\"user\": \"sdn\", \"password\":\"skyline\" ,\"domain\":\"sdn\"}}");//"{ \"login\": { \"user\": \"sdn\", \"password\": \"skyline\",\"domain\":\"sdn\" }}");

 

I also tried with ca-bundle.cert in place of pem.

 

I am using or writing an application in windows using curl and C.

 

Request you to please advice me. 

 

Regards,

Satish K

Highlighted
Frequent Advisor

Re: HP SDN VAN Controller - V2.0.0.4253 - Token Generation using LIB CURL

Hi Satish,

 

I'm not an expert on Curl, but do you set an URL with CURLOPT_URL somewhere and what is the value? I think that one is mandatory (see the example at the top of the thread).

 

Best Regards,

 

Wouter

 

SDN Team

Highlighted
Frequent Advisor

Re: HP SDN VAN Controller - V2.0.0.4253 - Token Generation using LIB CURL

Yes,, I set the OPT_URL.

 

Also I have created the ceft in my controller and using the same ceft. Even the pass phrase and SSLKEY I am using same.

 

Not sure where it is getting the problem with ceft

 

* Hostname was NOT found in DNS cache
* Trying 128.88.150.151...
* Connected to 128.88.150.151 (128.88.150.151) port 8443 (#0)
* unable to set private key file: 'sdnserver.pem' type PEM
* Closing connection 0
curl_easy_perform() failed: Problem with the local SSL certificate

Process returned 0 (0x0) execution time : 0.312 s
Press any key to continue.

 

Regards,

Satish K

 

Highlighted
Frequent Advisor

Re: HP SDN VAN Controller - V2.0.0.4253 - Token Generation using LIB CURL

Hi Satish,

 

Could you maybe post a snipped of all the SETOPT's that are done? Also maybe doing a run with CURLOPT_VERBOSE and CURLOPT_CERTINFO set might give some more detailed information?

 

Best regards,

 

Wouter

 

SDN Team

Highlighted
Frequent Advisor

Re: HP SDN VAN Controller - V2.0.0.4253 - Token Generation using LIB CURL

Hi,

 

Here is my complete code,

 

int main(void)
{
CURL *curl;
CURLcode res;

curl_global_init(CURL_GLOBAL_DEFAULT);

curl = curl_easy_init();
if(curl) {

struct curl_slist *slist = NULL;
/* -H Header */
slist = curl_slist_append(slist, "Content-type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);

/* URL */
curl_easy_setopt(curl, CURLOPT_URL, "https://128.88.150.151:8443/sdn/v2.0/auth");

/* -k option */
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1);
/* Proxy settings */
//curl_easy_setopt(curl, CURLOPT_PROXY, "http://172.16.150.32:8080/");
curl_easy_setopt(curl, CURLOPT_PROXY, "");
curl_easy_setopt(curl, CURLOPT_SSLKEY, "sdnserver"); // also tried with cakey, cacert
curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE, "PEM");
curl_easy_setopt(curl, CURLOPT_CAINFO, "sdnserver.pem"); //also tried with cacert.crt
curl_easy_setopt(curl, CURLOPT_SSLCERT, "sdnserver.pem");
curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

/* -X POST */
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"login\":{\"user\": \"sdn\", \"password\":\"skyline\" ,\"domain\":\"sdn\"}}");

/* -v option */
curl_easy_setopt(curl,CURLOPT_VERBOSE,1L);

/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));

/* always cleanup */
curl_slist_free_all(slist);
curl_easy_cleanup(curl);
}

curl_global_cleanup();

return 0;
}

Highlighted
Frequent Advisor

Re: HP SDN VAN Controller - V2.0.0.4253 - Token Generation using LIB CURL

Even I have created a self sigend ceft in my controller and same im using in client application. 

 

code as below,

curl_easy_setopt(curl, CURLOPT_PROXY, "");
curl_easy_setopt(curl, CURLOPT_SSLKEY, "server.key");
//curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE, "PEM");
curl_easy_setopt(curl, CURLOPT_CAINFO, "server.crt");
//curl_easy_setopt(curl, CURLOPT_SSLCERT, "server.crt");
curl_easy_setopt(curl, CURLOPT_CAPATH, "server");
curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

 

Getting the error as below,

 

* Hostname was NOT found in DNS cache
* Trying 128.88.150.151...
* Connected to 128.88.150.151 (128.88.150.151) port 8443 (#0)
* successfully set certificate verify locations:
* CAfile: server.crt
CApath: server
* SSL certificate problem: self signed certificate
* Closing connection 0
curl_easy_perform() failed: Peer certificate cannot be authenticated with given
CA certificates

Process returned 0 (0x0) execution time : 0.329 s
Press any key to continue.

 

PLease advice me,

 

Regards,

Satish K

Highlighted
Frequent Advisor

Re: HP SDN VAN Controller - V2.0.0.4253 - Token Generation using LIB CURL

Hi Satish,

 

Could you elaborate a bit on what your goal is? Are you trying to establish SSL communication with two way, one way, or no authentication? Thanks.

 

Wouter

 

SDN Team

Highlighted
Frequent Advisor

Re: HP SDN VAN Controller - V2.0.0.4253 - Token Generation using LIB CURL

Hi,

 

I want to establish a two way communication,

 

To communicate or access any API of controller, I need token which I can use in further request to communicate.

So this is what I am trying to access using the OpenSSL and Curl to get a token which can be used furhter.

 

I have written the Curl code in windows mc.

 

Regards,

Satish K