Arduino Mega, Ethernet, UDP, Radius problem ...

Hi,

I'm new in Arduino.

I'm working on a project and I would like to ask you for some help.

I have Arduino Mega 2560 with Ethernet Shield and TFT screen.

I need my program to read and show RADIUS Access Request on screen.

UDP reading works fine when I send package for testing from UDP sender app on my PC.

But when I try to read Radius UDP, it just shows that size iz 75 and content as empty (nothing shown).

I also tried to use RadiusMsg library that was published online by another user, but if I'm not wrong, it's client oriented so, I can't use it, because my program mus act as a server, not client.

As I said, with Ethernet.h library, I can not read data from radius request.

Can someone give me any idea, or link to anything that could help me?

Thank you and have a nice weekend :)

Don't you think that you should post the code you're writing about?

Sorry, yes I should.

But now I’ve passed that problem. Now I’m at new one.

I need to encrypt string of 16 octs in md5.

Here is my code, if anyone can help me.

Code:

    string = *replyBuffer;
    int length = sizeof(replyBuffer);
    const char *str = string;
    
    int n;
    md5_ctx c;
    unsigned char digest[16];
    char *out = (char*)malloc(33);

    md5_init(&c);
    md5_update(&c, str, length);
    md5_final(digest, &c);

    for(n = 0; n<16; ++n){
      snprintf(&(out[n*2]), 16*2, "%02x", (unsigned int)digest[n]);
    }

Errors:

ccKLpa1N.ltrans1.o:(.text.startup+0x47c): undefined reference to `md5_init(md5_ctx*)'

ccKLpa1N.ltrans1.o:(.text.startup+0x48e): undefined reference to `md5_update(md5_ctx*, unsigned char*, unsigned long)'

ccKLpa1N.ltrans1.o:(.text.startup+0x49e): undefined reference to `md5_final(unsigned char*, md5_ctx*)'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

Thank you all in advance.

Hi,

my problem was solved by changing md5.c to md5.cpp.

Now I have new problem.

I’m trying to encrypt radius response to access-request, so it’s access-accept.

If I’m right, that should be string from Code, ID, length, authenticator and shared secret (in my case “secret12”.

But as a result I receive only 2 octets let’s say “B5 C1” instead of 16 octets or more, I’m not 100%.

Thank you for all your help in advance :slight_smile:

PS: sorry, I’m new in arduino coding :slight_smile:

Code:

Declaration:

char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  //incomming UDP packet
char responseBuffer[UDP_TX_PACKET_MAX_SIZE];  //outgoing UDP packet
char replyBuffer[UDP_TX_PACKET_MAX_SIZE];  //extracted data from packetBuffer without atributes
char *string;
int packetSize;
md5_ctx c;
int n;
unsigned char digest[16];
char *out = (char*)malloc(33);

Extraction of string for encryption:

for(int i=0; i<20; i++){
    
    replyBuffer[i] = packetBuffer[i];
    
    }
  replyBuffer[20] = ("s");
  replyBuffer[21] = ("e");
  replyBuffer[22] = ("c");
  replyBuffer[23] = ("r");
  replyBuffer[24] = ("e");
  replyBuffer[25] = ("t");
  replyBuffer[26] = ("1");
  replyBuffer[27] = ("2");
}

MD5 coding:

string = *replyBuffer;
  md5_init(&c);
  md5_update(&c, string, sizeof(replyBuffer));
  md5_final(digest, &c);

  for(n=0; n<16; ++n){
    snprintf(&(out[n*2]), 16*2, "%02x", (unsigned int)digest[n]);
  }

MD5 print to screen:

tft.println("Data MD5: ");
  tft.println("Length: ");
  tft.println(sizeof(out));
  for(int i=0; i<sizeof(out); i++){
    uint8_t z;
    z=int(out[i]);
    tft.print(z, HEX);
    tft.print(" ");
  }
  tft.println("");

Creating string for response UDP:

responseBuffer[0]=2;
    for(int i=1; i<4; i++){
      responseBuffer[i] = packetBuffer[i];
    }
    for(int i=0; i<16; i++){
      responseBuffer[i+4] = out[i];
    }
    for(int i=20; i<packetSize; i++){
      responseBuffer[i] = packetBuffer[i];
    }

You should post complete code, not excerpts. Additionally explain what you’re trying to achieve, that might help us understand code with no comments a bit better.