thanks allot sir for reply. i have attached my code for certificate
authority i'm working with network simulator NS3 to simulate an AdHoc
network
what i want do is a certificate authority that provide me with
 1- create a certificate for all the nodes in the network should be 101
node and a certificate for the certificate authority itself
2- change the certificate into unsigned int in order to fit the simulator
packet structure
3- certificate authority should provide each node with the private key
which will be stored to be used later
i need help to construct this please and thanks allot for helping me


On Tue, Aug 26, 2014 at 2:26 PM, Mauricio Tavares <[email protected]>
wrote:

>
> On Aug 26, 2014 2:45 AM, "Amir Reda" <[email protected]> wrote:
> >
> > Dear all
> > I need your help for those points
> > 1- i want create 102 certificate from a certificate authority that i
> made ((101 node and 1 CA)
> > 2- change the certificate that i have created into unsigned int in order
> to fit the simulator that i work with as a header type i use NS3 simulator
> > please i need help
> >
>       What is the problem exactly? Post the cert creation script you wrote
> and the errors you are getting.
>
> > --
> > Warmest regards and best wishes for a good health,urs sincerely
> > mero
>



-- 
Warmest regards and best wishes for a good health,*urs sincerely *
*mero*
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:"nill"; -*- */
/*
 * Copyright (c) 2012 Amir Reda
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *Based on AeroRP 
 *Authors: Dr/ Sherif Khatab <[email protected]>
 *         Eng/ Amir mohamed Reda <[email protected]>
*/
#ifndef AeroRPCA_H
#define AeroRPCA_H

#include <iostream>
#include "ns3/header.h"
#include "ns3/ipv4-address.h"
#include "ns3/nstime.h"
#include "ns3/enum.h"
#include "ns3/simulator.h"
#include <map>

 namespace ns3 {
 namespace AeroRP {


 class CertificateAuthority
  {
 public:
  X509 CreateCertificate (uint32_t sn , X509_NAME name , RSA pubKey );

  void SetMyPrivateKey ();
  RSA GetMyPrivateKey ();
  void SetMyPublicKey (RSA caPrivateKey);
  RSA GetMyPublicKey ();
  RSA GeneratePrivateKey (int bits, unsigned long exp, void (*cb)(int, int, void), void *cb_arg );

 private:
 
 //std::map<Ipv4Address,std::pair <IssuerTableEntry , Time > > m_issuerTable;
 //std::map<Ipv4Address,std::pair <Certificate , Time > > m_certificate;
 RSA      m_caPublicKey;
 RSA      m_caPrivatekey;
};
}
}
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:"nill"; -*- */
/*
 * Copyright (c) 2012 Amir Reda
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *Based on AeroRP 
 *Authors: Dr/ Sherif Khatab <[email protected]>
 *         Eng/ Amir mohamed Reda <[email protected]>
*/


 namespace ns3 {
 namespace AeroRP {

 X509
 CertificateAuthority::CreateCertificate (uint32_t sn , X509_NAME name , RSA pubKey )
 {

    //create the certificate
    X509 * x509;
    x509 = X509_new();
    //add some x509 properties to the certificate
    ASN1_INTEGER_set(X509_get_serialNumber(x509), sn);
    //adds the specified number of seconds to the current time
    X509_gmtime_adj(X509_get_notBefore(x509), 0);
    //ets the certificate's notAfter property to 365 days from now 
    X509_gmtime_adj(X509_get_notAfter(x509), 31536000L);
    //set the key
    X509_set_pubkey(x509, pubKey);
    //set name
    X509_set_issuer_name(x509, name);
    X509_sign(x509, m_caPrivatekey, EVP_sha1());
 }

 void
 CertificateAuthority :: SetMyPrivateKey (int bits, unsigned long exp, void (*cb)(int, int, void), void *cb_arg )
 {
   // all the variables isn't changed i need to make them variables ????
   //create private key
   //EVP_PKEY * pkey;
   //pkey = EVP_PKEY_new();
   //generate rsa key
   m_caPrivatekey = GeneratePrivateKey(
    bits    //2048,/* number of bits for the key - 2048 is a sensible value */
    exp     //RSA_F4, /* exponent - RSA_F4 is defined as 0x10001L */
    cb      //NULL,   /* callback - can be NULL if we aren't displaying progress */
    cb_arg  //NULL    /* callback argument - not needed in this case */);
    //EVP_PKEY_assign_RSA(pkey, m_caPrivatekey);
 }

 RSA
 CertificateAuthority :: GetMyPrivateKey ()
 {
   return m_caPrivatekey;
 }

 void 
 CertificateAuthority :: SetMyPublicKey (RSA caPrivateKey)
 {
   
 }
 
 RSA
 CertificateAuthority :: GetMyPublicKey ()
 {
   return  m_caPublicKey;
 }

 RSA
 CertificateAuthority :: GeneratePrivateKey (int bits, unsigned long exp, void (*cb)(int, int, void), void *cb_arg )
 {
   return (*RSA_generate_key(int bits, unsigned long exp, void (*cb)(int, int, void),  void *cb_arg));
 }

}
}

Reply via email to